Ios Map: Getting Latitude and Longitude

I am trying to read longitude and latitude when a user touches (tap) on the ios Map, I want this particular place (the user's listening position) to place the latitude and longitude points. (for (ex), if the user touches the ios head office, I want to show the location of the head office at ios headquarters and the latitude point) . How can i do this. Anyone can help me solve this problem.

+1
source share
1 answer

Cancel the touch handler ( touchesBegan or UITapGestureRecognizer ), and then use - (CLLocationCoordinate2D)convertPoint:(CGPoint)point toCoordinateFromView:(UIView *)view in MKMapView , class reference here . Then add the appropriate annotation to the map using a class that conforms to the MKAnnotation protocol, for example. MKPinAnnotationView .

So, an example of the touch handler method would look something like this:

 -(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 this - there is a version of iOS5 on the same site.

+2
source

Source: https://habr.com/ru/post/985024/


All Articles