I would like to offer the user the possibility to (manually) select lat. and long. coordinates by touching a MKMapView
. How can I achieve that?
I've seen that the MKMapView
delegate offers the method convertPoint:toCoordinateFromView:
. I think, that could be a good starting, but I don't know how to create a point from a touch action.
I would appreciate any help. Thanks.
vwMap
is the name of MKMapview
object:
UITapGestureRecognizer *tapRecognizer = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(foundTap:)];
tapRecognizer.numberOfTapsRequired = 1;
tapRecognizer.numberOfTouchesRequired = 1;
[vwMap addGestureRecognizer:tapRecognizer];
-(IBAction)foundTap:(UITapGestureRecognizer *)recognizer {
CGPoint point = [recognizer locationInView:vwMap];
CLLocationCoordinate2D tapPoint = [vwMap convertPoint:point toCoordinateFromView:vwMap];
MKPointAnnotation *point1 = [[MKPointAnnotation alloc] init];
point1.coordinate = tapPoint;
[vwMap addAnnotation:point1];
}
A UITouch
object (see here) has the API:
- (CGPoint)locationInView:(UIView *)view
Then use the MKMapView
API you identified.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With