2
我一直在尝试几天,以便能够使用从相机拍摄的照片或从图库中选择的照片,并让它在地图上放置一个图钉图像只是选择/作为引脚。拍摄一张照片,并将它用作地图上的图钉
我能够成功地调出一个操作表并让用户选择/拍照。我也可以让用户放下一个别针。以下是我已经使用了这两种操作的代码:
//To take a photo
- (IBAction)takePhoto:(id)sender {
// Opens Action Sheet
UIActionSheet *actionSheet = [[UIActionSheet alloc] initWithTitle:@"Add a picture to the map" delegate:self cancelButtonTitle:@"Cancel" destructiveButtonTitle:nil otherButtonTitles:@"Take a picture",@"Choose from photos", nil];
[actionSheet showInView:self.view];
}
- (void) imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info {
UIImage *image = [info objectForKey:UIImagePickerControllerOriginalImage];
[imageView setImage:image];
[self dismissModalViewControllerAnimated:YES];
}
- (void) imagePickerControllerDidCancel:(UIImagePickerController *)picker {
[self dismissModalViewControllerAnimated:YES];
}
- (void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex {
picker2 = [[UIImagePickerController alloc] init];
picker2.delegate = self;
if (buttonIndex == 0) {
[picker2 setSourceType:UIImagePickerControllerSourceTypeCamera];
} else if (buttonIndex == 1) {
[picker2 setSourceType:UIImagePickerControllerSourceTypePhotoLibrary];
}
[self presentModalViewController:picker2 animated:YES];
}
//To drop a pin
[self.view addSubview:mapview];
MKCoordinateRegion region = {mapview.userLocation.location.coordinate.latitude,mapview.userLocation.location.coordinate.longitude};
CLLocationCoordinate2D myCoord = {mapview.userLocation.location.coordinate.latitude,mapview.userLocation.location.coordinate.longitude};
[mapview setCenterCoordinate:myCoord animated:YES];
region.span.longitudeDelta = 0.01f;
region.span.latitudeDelta = 0.01f;
[mapview setRegion:region animated:YES];
[mapview setDelegate:self];
Annotation *ann = [[Annotation alloc]initWithLocation:CLLocationCoordinate2DMake(37.616815,-122.389682)];
[mapview addAnnotation:ann];
ann.title = @"Start";
ann.subtitle = @"Subtitle for annotation";
ann.coordinate = myCoord;
ann.image = imageView;
[self setTitle:@"Map View"];
[mapview selectAnnotation:ann animated:YES];
[mapview addAnnotation:ann];
我我如何能整合这些在一起,使它所以拍摄的图像被用作针不确定,任何帮助是极大的赞赏。