【发布时间】:2011-07-28 05:20:46
【问题描述】:
我正在尝试从触摸事件中获取坐标。我可以捕捉到,但是当给缩放时有很大的数字,当我把它放在一个函数中时
newCoord = [mapView convertPoint:location toCoordinateFromView:mapView],
我得到了错误的坐标。我能做什么?
我的代码:
UITouch *touch = [touches anyObject];
CGPoint location = [touch locationInView:touch.view];
NSLog(@"locationTOUCH:%f,%f", location.x,location.y);
CLLocationCoordinate2D newCoord;
newCoord = [mapView convertPoint:location toCoordinateFromView:mapView];
NSLog(@"coordinate-%f,%f", newCoord.latitude,newCoord.longitude);
【问题讨论】:
-
touch.view和mapView一样吗?使用 UIGestureRecognizer 检测地图上的触摸可能会更好。见this answer。该答案没有提到您还应该在 shouldRecognizeSimultaneouslyWithGestureRecognizer 中返回 YES 以避免干扰地图的手势识别器。