嗨,我有一个使用谷歌地图的地图应用程序,一切正常,现在我想更改地图视图的方位,当我确认乘坐时单击类似Uber应用程序的按钮时,地图将继续更改方位直到找到驱动程序为止,它会恢复为默认值,而在没有驱动程序时,它将恢复为默认值。目前,我可以随用户旋转设备来旋转mapView,但如果用户不旋转,则方位不会自行改变。
所以我的问题是如何创建自定义轴承
下面是当用户旋转设备时我如何旋转mapView
func locationManager(_ manager: CLLocationManager, didUpdateHeading newHeading: CLHeading) {
mapView.animate(toBearing: newHeading.magneticHeading)
}
答案 0 :(得分:0)
只需引入属性并从一开始就存储新值。然后,当用户按下按钮时,从存储的值开始旋转地图。
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
}