我将Google表单从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
)提供相同的结果,但是我找不到类似的功能可以在mapbox中快速浏览。
有没有提供类似结果的swift函数?如果是,那会是什么?
答案 0 :(得分:1)
该功能不完全匹配,但mapView具有一个名为centerCoordinate的属性,该属性返回所需的值。
let mapCenter = mapView.centerCoordinate
更改/设置此属性将重置mapView的中心。如果需要,可以设置动画。
如果您想知道地图何时移动然后停止,可以使用委托方法:
fun mapView(_ mapView: MGLMapView, regionDidChangeAnimated: Bool) {
// Get your centre coordinate here.
}
只要当前显示的地图摄像机完成更改,就会调用此方法。