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

I switch between three different map orientation modes using MKUserTrackingModeNone , MKUserTrackingModeFollow , MKUserTrackingModeFollowWithHeading , and it works.

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

In an embedded card application on an iphone/ipad stream is as follows:

When you start the application, it is in MKUserTrackingModeNone mode and oriented north. When you switch 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 in accordance with the direction you are in / point the iPhone.

When you switch the orientation again, it returns to MKUserTrackingModeNone , and the map rotates well back to the north orientation.

I would like my application to relate to orientation in switch mode as well, but when I do this as in step 4 above and switch from MKUserTrackingModeFollowWithHeading to MKUserTrackingModeNone , the orientation remains the same making the orientation switch instead of rotating back to the north orientation.

I set the orientation switch with the standard MKUserTrackingBarButtonItem control located on the toolbar.

Can someone please help me solve this problem?

+4
source share
3 answers

I also encounter this issue on iPhone 5 running iOS 6.1.4. I used this simple but ugly quick fix to make the map screen rotate 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 is probably a much better way to do this, but I haven't found it yet.

+1
source

In iOS 5, it will switch north for you, but in iOS 6 it is not. You can request an improvement at bugreport.apple.com.

You can implement the delegate callback function and apply the rotation in the delegate callback ...

 - (void)mapView:(MKMapView *)mapView didChangeUserTrackingMode:(MKUserTrackingMode)mode animated:(BOOL)animated { if (mode == MKUserTrackingModeNone) [self rotateTheMapView]; } - (void)rotateTheMapView { // See https://stackoverflow.com/q/1245461/1445366 } 

(See Turn MapView using compass orientation for instructions and turn code.)

The problem is that Apple does not expose the exact pinpoint rotation with its internal logic, so any calculations from the current header provided to you by iOS may be slightly disabled, which leads to the fact that your map will be a little north, made.

0
source

You need to build a small test application that only has a map and MKUserTrackingBarButtonItem, and link them together. If you need to do this, as you described, and does not require a separate line of code. All connections can be made in IB. Once you see that you are working, you can return to your code and repeat the process.

0
source

All Articles