Not many people are aware of this but the Maps app on the iPhone and iPad allows you to tap and hold to drop an annotation/pin on the map.
Once the pin is dropped the App uses reverse geocoding (available with MapKit – details here) to get location details for a specific coordinate.
I’ve been working on a project where I’d like to allow users to submit locations by tapping on the map. It turns this is pretty easy to implement:
First we need to setup a gesture recogniser for a long press (tap and hold)
UILongPressGestureRecognizer *longPressGesture = [[UILongPressGestureRecognizer alloc] initWithTarget:self action:@selector(handleLongPressGesture:)];
Next we create the handleLongPressGesture: method which will handle the tap and hold action
// This is important if you only want to receive one tap and hold event
if (sender.state == UIGestureRecognizerStateEnded)
// Here we get the CGPoint for the touch and convert it to latitude and longitude coordinates to display on the map
CGPoint point = [sender locationInView:self.mapView];
CLLocationCoordinate2D locCoord = [self.mapView convertPoint:point toCoordinateFromView:self.mapView];
// Then all you have to do is create the annotation and add it to the map
YourAnnotation *dropPin = [[YourAnnotation alloc] init];
dropPin.latitude = [NSNumber numberWithDouble:locCoord.latitude];
dropPin.longitude = [NSNumber numberWithDouble:locCoord.longitude];
And that should do the trick! Let me know how you go and if you have any questions in the comments section below.