【问题标题】:How to get the lat/long in MapBox iOS SDK after drag&drop拖放后如何在 MapBox iOS SDK 中获取纬度/经度
【发布时间】:2018-11-16 09:15:01
【问题描述】:

我使用拖放的方式与 MapBox 的官方示例相同: https://www.mapbox.com/ios-sdk/maps/examples/draggable-views/

我无法找到一种方法来获取拖放后被拖动注释的纬度/经度。 没有代表。在 MGLMapViewDelegate 和任何其他委托中都没有。

MGLAnnotationView 有一些与纬度/经度请求不匹配的拖动状态成员。 https://www.mapbox.com/ios-sdk/api/4.6.0/Classes/MGLAnnotationView.html

当我使用 initWithAnnotation:reuseIdentifier: 而不是 initWithReuseIdentifier: MGLAnnotationView 的注解属性设置正确。但是 annotation.coordinate 没有得到更新。

https://www.mapbox.com/ios-sdk/api/4.6.0/Classes/MGLAnnotationView.html#/c:objc(cs)MGLAnnotationView(im)initWithAnnotation:reuseIdentifier:

那么我怎样才能得到下降后的纬度/经度呢?

【问题讨论】:

    标签: ios drag-and-drop mapbox


    【解决方案1】:

    如果我的理解正确,这应该就像在拖动完成后检查与 annotationView 关联的注释一样简单。

    您是否在可拖动的 MGLAnnotationView 子类中尝试过类似以下的操作?

    let newLatitude = self.annotation?.coordinate.latitude
    let newLongitude = self.annotation?.coordinate.longitude
    

    -- 允许通常的可选检查等。我在endDragging() 方法中有这些行。

    【讨论】:

    • 是的,你是对的。在 MGLAnnotationViewDragStateDragging 期间,坐标不会更新。但是MGLAnnotationViewDragStateEnding注解的坐标被更新了。
    【解决方案2】:

    关联注释的坐标仅在结束时更新,而不是在拖动期间。

        case MGLAnnotationViewDragStateDragging:
            NSLog(@"%@ / %@", @(self.annotation.coordinate.latitude), @(self.annotation.coordinate.longitude));
            break;
    
        case MGLAnnotationViewDragStateEnding:
        case MGLAnnotationViewDragStateCanceling:
            NSLog(@"endDragging: %@ / %@", @(self.annotation.coordinate.latitude), @(self.annotation.coordinate.longitude));
            [self endDragging];
            break;
    

    结果:

    2018-11-17 10:15:22.122488+0100 FreeFlightAtlas AdHoc[4780:1555191] -34.613152 / -58.377232
    2018-11-17 10:15:22.145187+0100 FreeFlightAtlas AdHoc[4780:1555191] -34.613152 / -58.377232
    2018-11-17 10:15:22.169465+0100 FreeFlightAtlas AdHoc[4780:1555191] -34.613152 / -58.377232
    2018-11-17 10:15:22.193490+0100 FreeFlightAtlas AdHoc[4780:1555191] -34.613152 / -58.377232
    2018-11-17 10:15:22.485666+0100 FreeFlightAtlas AdHoc[4780:1555191] endDragging: 25.12811184395072 / -41.88967123348579
    

    【讨论】:

      猜你喜欢
      • 2016-10-30
      • 1970-01-01
      • 2014-11-26
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2023-01-13
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多