1

I got a MKMapView with an overlay that allows the user to finger paint over a MKMapView. I know what a finger-drawn line is in terms of X,Y points. What I would like to know is how to convert this array of X,Y points into coordinate2D objects (latitude, longitude).

The way I see it is : a user opens the overlay map, scrolls to anywhere, then draws a line over the map, each point on the line gets converted to a coordinate2D and the map kit drops a pin at each coordinate.

I know that the center coordinate of the map view may be queried, but I'm not sure of how to calculate the coordinates of points that are offset from the center. I know that latitude and longitude are slightly "curvy", so it's not a simple offset equation.

Are there any open source or sample projects on how to convert map view touches to coordinates?

PS. I intend to use this for iPhone-controlled robot project to set waypoints for the robot.

Alex Stone
  • 46,408
  • 55
  • 231
  • 407

1 Answers1

3

Apply gesture recognizer and then try below code to get the co-ordinate on view and then convert them into latitude and longitude.

CGPoint touchPoint = [gestureRecognizer locationInView:self.mapView];   
    CLLocationCoordinate2D touchMapCoordinate = 
        [self.mapView convertPoint:touchPoint toCoordinateFromView:self.mapView];

NOTE : Not tested, but seems like this will work, This should work without overlay

Code credit goes to : How to add a push pin to a MKMapView(IOS) when touching? 's accepted answer

Community
  • 1
  • 1
TeaCupApp
  • 11,316
  • 18
  • 70
  • 150