【问题标题】:Get coordinates upon mapview gesture获取地图视图手势的坐标
【发布时间】:2011-08-15 14:02:38
【问题描述】:

我如何获得用户在mapView上进行longhold(例如2s)的点的纬度和经度。

我偶然发现了一个类似的问题:get coordinates on tap in iphone application

但我不明白如何处理 mapView 上的触摸事件。

我打算实现它的目的是在该位置放置一个 pin 注释,通过 Google API 进行必要的反向地理编码并将其显示在字幕上。所以首先,我需要获取所需的坐标。

非常感谢您提供示例。

谢谢。

【问题讨论】:

    标签: iphone xcode android-mapview touch-event


    【解决方案1】:

    您可以像这样将从手势检索到的视图中的触摸坐标转换为 gps 坐标...

    - (void)mapLongPress:(UILongPressGestureRecognizer *)gestureRecognizer{
        if(gestureRecognizer.state == UIGestureRecognizerStateBegan){
            CGPoint touchLocation = [gestureRecognizer locationInView:mapView];
    
            CLLocationCoordinate2D coordinate;
            coordinate = [mapView convertPoint:touchLocation toCoordinateFromView:mapView];
        }
    }
    

    请注意,在我的示例中,我将手势应用于 mapView 本身。您必须将应用手势的视图传递给toCoordinateFromView:mapView

    【讨论】:

    • 太棒了。只需在 viewDidLoad UILongPressGestureRecognizer *longPressGesture = [[UILongPressGestureRecognizer alloc] initWithTarget:self action:@selector(mapLongPress:)] 中添加以下内容longPressGesture.minimumPressDuration = 2; [mapView addGestureRecognizer:longPressGesture]; [longPressGesture 发布];
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2015-11-16
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-04-30
    • 2015-03-28
    相关资源
    最近更新 更多