【问题标题】:Is there a function like (MapboxMap.OnCameraIdleListener) in swift 4?swift 4中是否有类似(MapboxMap.OnCameraIdleListener)的功能?
【发布时间】:2018-12-21 05:58:16
【问题描述】:

我从谷歌地图切换到 MapBox,但找不到类似的功能:

func mapView(_ mapView: GMSMapView, idleAt cameraPosition: GMSCameraPosition) {
geocoder.reverseGeocodeCoordinate(cameraPosition.target) { (response, error) in
  guard error == nil else {
    return
  }

  if let result = response?.firstResult() {
    let marker = GMSMarker()
    marker.position = cameraPosition.target
    marker.title = result.lines?[0]
    marker.snippet = result.lines?[1]
    marker.map = mapView
  }
}
 }
}

当用户停止移动地图时,它会给出地图中心的坐标,我还发现有一个 mapBox 的功能,它可以为 android (MapboxMap.OnCameraIdleListener) 提供相同的结果,但我找不到类似的功能在 mapbox 中用于 swift。

是否有 swift 的功能可以提供类似的结果?如果是,那可能是什么?

【问题讨论】:

    标签: swift mapbox


    【解决方案1】:

    该函数不完全匹配,但 mapView 有一个名为 centerCoordinate 的属性,它返回您想要的值。

    let mapCenter = mapView.centerCoordinate
    

    更改/设置此属性将重置mapView’s 中心。如果需要,可以设置动画。

    如果您想知道地图何时移动然后停止,您可以使用委托方法:

    func mapView(_ mapView: MGLMapView, regionDidChangeAnimated: Bool) {
        // Get your centre coordinate here.
    }
    

    只要当前显示的地图相机完成更改,就会调用此方法。

    【讨论】:

      猜你喜欢
      • 2012-08-01
      • 2023-04-07
      • 1970-01-01
      • 1970-01-01
      • 2021-11-14
      • 2015-11-21
      • 1970-01-01
      • 2016-08-08
      • 2019-12-19
      相关资源
      最近更新 更多