6

How can I get the location coordinates in mkmapview according to user touching a location on the map on their iphone?

Vadim Kotov
  • 8,084
  • 8
  • 48
  • 62
  • I want to get coordinates of location when user touches in mkmapview.I mean when user touches on some city then i want to get that location's coordinates. Now am not able to get point in which user touches in mkmapview. –  Aug 17 '11 at 04:10
  • can you understand my problem in display annotations in mkmapview –  Aug 20 '11 at 15:49
  • Hope [this][1] article should help you. [1]: http://stackoverflow.com/questions/3080198/get-the-coordinates-of-a-point-from-mkmapview-on-iphone – Anton Sivov Nov 08 '11 at 09:29

2 Answers2

3
func touchesBegan(_ touches: Set<UITouch>, with event: UIEvent?) {

    for touch in touches {
        let touchPoint = touch.location(in: mapView)
        let location = mapView.convert(touchPoint, toCoordinateFrom: mapView)
        print ("\(location.latitude), \(location.longitude)")
    }
}
Unheilig
  • 16,196
  • 193
  • 68
  • 98
0

Add TapGesture to you mapview and follow below code

-(void)didTouchMap:(UITapGestureRecognizer*)tapGesure {

         CGPoint touchPoint = [tapGesure locationInView:selectLocationMapView];
         CLLocationCoordinate2D coord= [selectLocationMapView convertPoint:touchPoint      toCoordinateFromView:selectLocationMapView];
         NSLog(@"lat  %f",coord.latitude);
         NSLog(@"long %f",coord.longitude);

}
Vadim Kotov
  • 8,084
  • 8
  • 48
  • 62
Kuntal Gajjar
  • 792
  • 6
  • 12