2013-02-20 89 views
1

我试图读取用户在ios地图上触摸(点击)地图上的经度和纬度,我想要获取该特定地点(用户点击地点)放置经度和纬度点。 (对于(e.x)如果用户触摸ios总部意味着我想显示ios总部位置的经度和纬度点)。我怎样才能做到这一点。任何人都可以帮助我解决这个问题。Ios地图:获取经纬度

回答

2

覆盖触摸处理器(touchesBeganUITapGestureRecognizer),然后在MKMapView,类参考 here使用 - (CLLocationCoordinate2D)convertPoint:(CGPoint)point toCoordinateFromView:(UIView *)view。然后,使用符合MKAnnotation协议的类(例如,)添加适当的注释到地图。 MKPinAnnotationView

所以一个例子触摸处理方法看起来是这样的:

-(void)touchesBegan:(NSSet*)touches withEvent:(UIEvent*)event 
{ 
    CGPoint pt = [[touches anyObject]locationInView:self.mapView]; 
    CLLocationCoordinate2D latLong = [self.mapView convertPoint:pt toCoordinateFromView:self.mapView]; 
    //add code here for annotation 
} 

然后添加注释 - 本教程http://www.raywenderlich.com/21365/introduction-to-mapkit-in-ios-6-tutorial应帮助您觉得─有在同一地点的iOS5的版本,以及。

+0

嗨。感谢您的回复。你可以给我任何示例代码。 – kannan 2013-02-20 11:22:49

+0

我已经添加了一个示例方法,显示如何获得答案的坐标。您需要查看文档以及可能的注释材料的一些教程 - 我还添加了一个指向 – 2013-02-20 11:45:16

+0

的链接感谢您的回复 – kannan 2013-02-21 05:10:54