ios - map View 的自定义方位角旋转

标签 ios swift google-maps

嗨,我有一个 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/

相关文章:

ios - swift中的无限长度数组

javascript - Google Maps Javascript API 自定义控件下拉菜单

google-maps - xamarin.forms map 隐藏缩放按钮 (+-)

java - Android 将 Json 对象添加到 google 标记

ios - 获取标签栏高度的错误值?

iphone - 在 UILabel 中显示变量

enums - 如何在 Swift 中指定类型约束为枚举?

swift - 在 Swift 中模拟单例/sharedInstance

ios - 在 collectionview 上滚动后 dequeueReusableCellWithReuseIdentifier 出错了

ios - 如何检测我是否点击了 SKShapeNode