我想为用户提供(手动)选择lat的可能性。而且很长。触摸MKMapView
进行坐标。我怎样才能做到这一点?
我看到MKMapView
委托提供方法convertPoint:toCoordinateFromView:
。我认为,这可能是一个很好的开始,但我不知道如何通过触摸动作创建一个点。
我将不胜感激任何帮助。感谢。
答案 0 :(得分:10)
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];
}
答案 1 :(得分:6)