Michael Matus
Michael Matus

Reputation: 1

compass vanishes when MKMap is oriented to north in iOS

I am displaying a map on the iPhone using MKMapView. The Map can rotate so that it is oriented with respect to the iPhone orentation using the magnetic heading information.

I like to present the compass but it vanishes each time the map is oriented to north! It reappears when the phone is rotated a little bit further but this is distracting.

The rotation functionality is switched on when some conditions are met like so:

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

The rotation is performed by a delegate:

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

The CoreLocation stuff is encapsulated in the locationService singleton.

How can one force to show the compass also when the map is oriented exactly to north? I guess this behavior is a feature not a bug which seems to be undocumented. (found in iOS 9 and iOS 10)

Upvotes: 0

Views: 433

Answers (1)

Kosuke Ogawa
Kosuke Ogawa

Reputation: 7451

You're right. This behavior is a feature not a bug.

In iOS 11 you can use compassVisibility.

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

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

enter image description here

Upvotes: 1

Related Questions