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];
내가 함께 이들을 통합하고 촬영 한 이미지가 핀으로 사용되도록 그것을 만들 수있는 방법에 확실 해요, 어떤 도움을 크게 감사합니다.