Ios Map:获取经度和纬度 [英] Ios Map: Getting latitude and longitude
问题描述
我试图在用户触摸(点击)ios Map地点时读取经度和纬度我希望得到特定的(用户点击位置)放置纬度和经度点。
(对于(e.x),如果用户触摸ios总部意味着我想显示ios总部位置经度和纬度点)。我怎样才能做到这一点。任何人都可以帮我解决这个问题。
Am trying to read the longitude and latitude when the user touch (tap) on the ios Map place i want to get that particular (user tapping place) place latitude and longitude points. (for (e.x) if the user touch the ios head office means i want to show ios head office place longitude and latitude points). How can i do this. Any one can help me to solve this issue.
推荐答案
覆盖触摸处理程序( touchesBegan
或 UITapGestureRecognizer
)然后使用
- (CLLocationCoordinate2D)convertPoint:(CGPoint)指向CoordinateFromView :( UIView *)视图
in MKMapView
,类引用这里。然后使用符合 MKAnnotation
协议的类,向地图添加适当的注释,例如 MKPinAnnotationView
。
Override a touch handler (touchesBegan
or UITapGestureRecognizer
) and then use
- (CLLocationCoordinate2D)convertPoint:(CGPoint)point toCoordinateFromView:(UIView *)view
in MKMapView
, class reference here. Then add an appropriate annotation to the map using a class conforming to the MKAnnotation
protocol, e.g. MKPinAnnotationView
.
因此,示例触摸处理程序方法如下所示:
So an example touch handler method would look something like:
-(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版本。
Then add the annotation - this tutorial http://www.raywenderlich.com/21365/introduction-to-mapkit-in-ios-6-tutorial should help you with that- there's an iOS5 version on the same site as well.
这篇关于Ios Map:获取经度和纬度的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!