当MKMap在iOS中面向北方时,指南针消失了

时间:2017-08-21 05:46:39

标签: ios iphone swift mapkit

我正在使用MKMapView在iPhone上显示地图。地图可以旋转,以便使用磁航向信息相对于iPhone的定向进行定向。

我喜欢展示指南针,但每次地图朝向北方时它都会消失!当手机稍微旋转一下时再次出现,但这会分散注意力。

当满足某些条件时,旋转功能会打开:

@IBOutlet weak var mapView: MKMapView!
// here comes some other code
if settings.useMagneticHeading && validUserLocation
{
   mapView.isRotateEnabled = true
   mapView.showsCompass = true
   locationService.startUpdatingHeading()
}

轮换由代表执行:

func tracingHeading(currentHeading: CLLocationDirection)
{
    if settings.useMagneticHeading && validUserLocation
    {
        mapView.camera.heading = currentHeading
        mapView.setCamera(mapView.camera, animated: true)
    }
}

CoreLocation内容封装在locationService单例中。

当地图完全朝向北方时,如何强制显示指南针?我想这个行为是一个功能,而不是一个似乎没有记录的错误。 (在iOS 9和iOS 10中找到)

1 个答案:

答案 0 :(得分:1)

你是对的。此行为是一个功能,而不是错误。

在iOS 11中,您可以使用compassVisibility

let compass = MKCompassButton(mapView: mapView)
compass.compassVisibility = .visible

https://developer.apple.com/documentation/mapkit/mkcompassbutton/2890262-compassvisibility

enter image description here