gpt4 book ai didi

swift - swift 4 中是否有类似 (MapboxMap.OnCameraIdleListener) 的功能?

转载 作者:行者123 更新时间:2023-11-28 13:55:57 26 4
gpt4 key购买 nike

我从谷歌地图切换到 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
}
}
}
}

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

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

最佳答案

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

let mapCenter = mapView.centerCoordinate

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

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

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

This method is called whenever the currently displayed map camera has finished changing.

关于swift - swift 4 中是否有类似 (MapboxMap.OnCameraIdleListener) 的功能?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53879873/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com