代码之家  ›  专栏  ›  技术社区  ›  TheSwiftGuy77

在Swift 4中是否有类似(mapboxmap.oncamerraidlelistener)的功能?

  •  0
  • TheSwiftGuy77  · 技术社区  · 7 年前

    我从google map切换到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 )但在Swift的地图框中找不到类似的功能。

    Swift是否有类似结果的函数?如果是,那可能是什么?

    1 回复  |  直到 7 年前
        1
  •  1
  •   Magnas    7 年前

    函数没有完全匹配,但mapview有一个名为centercoordinate的属性,该属性返回所需的值。

    let mapCenter = mapView.centerCoordinate
    

    更改/设置此属性将重置地图视图中心。如果需要,可以设置动画。

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

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

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