嗨,我有一个 map 应用程序,我在其中使用了谷歌地图,一切正常,现在我想更改 map View 的方位,当我在确认乘车时单击优步应用程序之类的按钮时, map 会继续更改方位直到找到驱动程序,它才返回默认值,当没有驱动程序时,它返回默认值。目前,我可以在用户旋转设备时旋转 map View ,但如果用户不这样做,方位不会自行改变。
so My question is how how to create custom bearings
下面是当用户旋转设备时我如何旋转 map View
func locationManager(_ manager: CLLocationManager, didUpdateHeading newHeading: CLHeading) {
mapView.animate(toBearing: newHeading.magneticHeading)
}
最佳答案
只需引入属性并从一开始就存储新值。然后,当用户按下按钮时,根据存储的值旋转 map 。
var knownHeading: CLHeading
var buttonPushed = false
func locationManager(_ manager: CLLocationManager, didUpdateHeading newHeading: CLHeading) {
if buttonPushed {
mapView.animate(toBearing: newHeading.magneticHeading)
} else {
knownHeading = newHeading
}
}
@IBAction func buttonPushed() {
mapView.animate(toBearing: knownHeading.magneticHeading)
buttonPushed = true
//your other code here
}
关于ios - map View 的自定义方位角旋转,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55475312/