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.