Skip to content

Instantly share code, notes, and snippets.

@a1phanumeric
Created March 30, 2012 08:23
Show Gist options
  • Save a1phanumeric/2249553 to your computer and use it in GitHub Desktop.
Save a1phanumeric/2249553 to your computer and use it in GitHub Desktop.
Convert MKMapView touch to coordinate
UILongPressGestureRecognizer *lpgr = [[UILongPressGestureRecognizer alloc] initWithTarget:self action:@selector(handleLongPress:)];
lpgr.minimumPressDuration = 1.0;
[self.mapView addGestureRecognizer:lpgr];
// ---------------------------------
- (void)handleLongPress:(UIGestureRecognizer *)gestureRecognizer{
if (gestureRecognizer.state != UIGestureRecognizerStateBegan)return;
CGPoint touchPoint = [gestureRecognizer locationInView:self.mapView];
CLLocationCoordinate2D touchCoordinate =
[self.mapView convertPoint:touchPoint toCoordinateFromView:self.mapView];
NSLog(@"%f, %f", touchCoordinate.latitude, touchCoordinate.longitude);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment