开发者

Get coordinates upon mapview gesture

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.


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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜