点触缩放mapView

Posted

技术标签:

【中文标题】点触缩放mapView【英文标题】:Point touch with zoom mapView 【发布时间】: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 以避免干扰地图的手势识别器。 【参考方案1】:

我猜它应该通过改变来解决

CGPoint location = [touch locationInView:touch.view];

CGPoint location = [touch locationInView:mapView];

【讨论】:

Ortwin 是对的:视图的坐标系可能不一样,这就是为什么使用一个用于触摸检测而另一个用于坐标转换时会得到错误的坐标。

以上是关于点触缩放mapView的主要内容,如果未能解决你的问题,请参考以下文章