我希望能够让用户通过触摸 MKMapView
来手动选择纬度和经度坐标。我该如何实现呢?
我注意到 MKMapView
委托提供了方法 convertPoint:toCoordinateFromView:
。我认为这可能是一个好的起点,但是我不知道如何从触摸操作中创建一个点。
如果有任何帮助,我将不胜感激。谢谢。
vwMap
是MKMapView
对象的名称:
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];
}