Ios Map: Getting latitude and longitude

丶灬走出姿态 提交于 2019-12-11 11:43:03

问题


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.


回答1:


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 
}

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.



来源:https://stackoverflow.com/questions/14978203/ios-map-getting-latitude-and-longitude

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!