i add MKPinAnnotationView and setDragAble. my code is here
- (MKAnnotationView *)mapView:(MKMapView *)mapView viewForAnnotation:(id <MKAnnotation>)annotation {
MKPinAnnotationView *annotationView = [[MKPinAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:@"pin"];
[annotationView setDraggable:YES];
annotationView.pinColor = MKPinAnnotationColorPurple;
return [annotationView autorelease];
}
ok i can drag pin.
but one problem is it's not just one tap. always need second tap.
when i first tap pin is selected but can't drag. when i tap again it's available drag.
what's wrong? i want just one tap drag like "Map.app"
Reslove this problem. ^^
i think for drag pin, pin is already selected.
so selected MKPinAnnotationView when it init.
my new code.
- (MKAnnotationView *)mapView:(MKMapView *)mapView viewForAnnotation:(id <MKAnnotation>)annotation {
MKPinAnnotationView *annotationView = [[MKPinAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:@"pin"];
[annotationView setDraggable:YES];
annotationView.pinColor = MKPinAnnotationColorPurple;
[annotationView setSelected:YES animated:YES];
return [annotationView autorelease];
}
The answers here doesn't account for when you tap on a pin first and deselect it after, then the dragging problem will return because mapView deselects the annotation view. I came accross a new solution and that is selecting the annotationview that just got deselected in:
-(void)mapView:(MKMapView *)mapView didDeselectAnnotationView:(MKAnnotationView *)view
{
[view setSelected:YES];
}
This will save you from all the frustration. The beauty of it is that this is all you need! You don't need to set the pins as selected at all.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With