Disable compass on MKMapView

BlackM picture BlackM · Oct 5, 2013 · Viewed 12.8k times · Source

I am using a MapView in my app to show some annotations. In iOS 7 a compass appears randomly on the map. I can't reproduce the error because it appears randomly but I want to disable it. Any ideas how to disable it?

Update: I found out is not appears randomly but on a specific gesture. When you use 2 fingers and slide one right and the other left.

Answer

Mark Amery picture Mark Amery · Oct 5, 2013

You can disable the compass easily on OSX 10.9 / iOS 9 and later with the showsCompass property:

yourMapView.showsCompass = NO;

On iOS 8 or earlier, your choices are:

  1. Suck it up and live with it.

  2. Use a hack, like:

  3. If you're not rotating the map programatically and it hasn't already been rotated, disable rotation entirely, using

    mapView.rotateEnabled = NO;
    

    The compass only shows up when the map is rotated, so by doing this you ensure that the compass is never triggered.

It's not clear to me why Apple waited so long to allow hiding the compass on iOS, and none of the options above are ideal. Pick whichever you think is the least bad in your case.