Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to keep MKMapView in iOS 6 North oriented always when switching mode from MKUserTrackingModeFollowWithHeading

I am switching between the three different map orientation modes using MKUserTrackingModeNone, MKUserTrackingModeFollow, MKUserTrackingModeFollowWithHeading and this works.

However I have a problem with the orientation of the map not resetting to north-facing orientation (north on the map being at the top of the screen) when switching from MKUserTrackingModeFollowWithHeading to MKUserTrackingModeNone.

On the built-in maps app on the iphone/ipad, the flow is like this:

When you start the app it is in mode MKUserTrackingModeNone and is north-oriented When you toggle the orientation mode it changes to MKUserTrackingModeFollow, and the orientation is still north.

When you switch again, it changes to MKUserTrackingModeFollowWithHeading, and the map rotates according to the direction you are facing/pointing the iPhone.

When you switch orientation again, it goes back to MKUserTrackingModeNone, and the map nicely rotates back to being north-oriented.

I would like my app to behave in the same way in regards to orientation when switching mode, but when I do as in step 4 above and switch from MKUserTrackingModeFollowWithHeading to MKUserTrackingModeNone, the orientation stays as it was just before making the orientation switch instead of rotating back to north orientation.

I am making the orientation switch with the standard MKUserTrackingBarButtonItem control placed in a toolbar.

Anyone please help me to fix this issue?

like image 881
real hat Avatar asked Apr 13 '13 05:04

real hat


1 Answers

I'm also running into this issue on an iPhone 5 running iOS 6.1.4. I used this simple but ugly quick fix to force the map view to rotate back to North up:

-(void)someMethod
{
    // Currently in MKUserTrackingModeFollowWithHeading mode

    // Set tracking mode back to MKUserTrackingModeFollow
    [_mapView setUserTrackingMode:MKUserTrackingModeFollow];

    // After a short delay, set mode to MKUserTrackingModeNone
    [self performSelector:@selector(mapViewTrackingModeNone)
               withObject:nil
               afterDelay:0.2];

}

- (void)mapViewTrackingModeNone
{
    [_mapView setUserTrackingMode:MKUserTrackingModeNone];

    // Bang! The map rotates back to North-Up
}

There's probably a much better way to do this, but I haven't found it yet.

like image 130
Dylan Avatar answered Oct 23 '22 02:10

Dylan