How to rotate iOS MKMapView so that it north-oriented when switching tracking mode?
Asked Answered
C

2

2

I am working on an iPad app (iOS 5.1), and I use MKMapView to display a map in my app.

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 ipad, the flow is like this:

  1. When you start the app it is in mode MKUserTrackingModeNone and is north-oriented
  2. When you toggle the orientation mode it changes to MKUserTrackingModeFollow, and the orientation is still north.
  3. When you switch again, it changes to MKUserTrackingModeFollowWithHeading, and the map rotates according to the direction you are facing/pointing the iPad.
  4. 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.

Any ideas of how to solve this?

Thanks!

Contractive answered 9/6, 2012 at 18:33 Comment(0)
L
0

Are you using the standard iOS button bar item for doing this? My app does and as soon as I tap it from followWithHeading to non it rotates back to north is up.

Lebensraum answered 10/6, 2012 at 19:1 Comment(2)
Hi Craig. Yes, I am using the standard iOS button bar item, but it doesn't behave in the same way as it seems to do in your app. What version of SDK are you using? And have you tested it on an iPad 2 (this is what I am testing my app on)?Contractive
I'm running it on iOS 5.1.1 on my iPhone 4s. I believe I have tried it on 5.1 on an iPad 2 when I borrowed one during testing a few months ago.Lebensraum
A
0

This is a quick fix that works, though it's not very elegant:

https://mcmap.net/q/1832816/-how-to-keep-mkmapview-in-ios-6-north-oriented-always-when-switching-mode-from-mkusertrackingmodefollowwithheading

Aeriela answered 16/5, 2013 at 18:31 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.