1
votes

How do I get the latitude and longitude on the point where the user do a longhold(eg 2s)on the mapView.

I chanced upon a similar question : get coordinates on tap in iphone application

But I don't understand how do I go about handling the touch event on the mapView.

What I intent to achieve it to drop a pin annotation to the location, do nesscary reverse geocoding via Google API and display it on the subtitle. So firstly, I would need to get the required coordinates.

Examples would be very much appreciated.

Thanks.

1

1 Answers

4
votes

You can convert the coordinates of the touch in the view retrieved from the gesture to gps coordinates like this...

- (void)mapLongPress:(UILongPressGestureRecognizer *)gestureRecognizer{
    if(gestureRecognizer.state == UIGestureRecognizerStateBegan){
        CGPoint touchLocation = [gestureRecognizer locationInView:mapView];

        CLLocationCoordinate2D coordinate;
        coordinate = [mapView convertPoint:touchLocation toCoordinateFromView:mapView];
    }
}

Note that in my example, I had the gesture applied to the mapView itself. You would have to pass the view to which you applied the gesture to toCoordinateFromView:mapView