-2

Code:

map.UserTrackingMode = MKUserTrackingMode.FollowWithHeading;

But after a user interacts with the map or after mKMapView.ShowAnnotations, the map automatically stops following the device's heading. (Not by my code. That's just how mkmapview works. This is also the case in the built in Maps app.)

How can I make the map start following the device's heading again from code?

ispiro
  • 26,556
  • 38
  • 136
  • 291
  • In general you don’t. You are expected to provide a tracking button so the user can change tracking mode. – matt Nov 18 '19 at 20:38
  • @matt And when the user clicks that button, what code needs to run? If you mean the code above - that's not the case because it's already set. And if you mean that the tracking mode shouldn't change until the user clicks on that button to change it - that would be great, but unfortunately that's not the case because when the user interacts with the map (or ShowAnnotations is called) the map ***automatically*** stops following the heading. – ispiro Nov 18 '19 at 21:17
  • You don't need to do anything. The map view gives you the button; all you do is put it into the interface, associating it with the map view. It operates automatically when the user taps it. This works exactly like the Maps app and is just what the user expects anyway. The whole behavior where the map stops tracking when the user scrolls is totally normal and expected, no problem. – matt Nov 18 '19 at 21:45
  • @matt Thanks. I wasn't aware of the fact that I can add the button to my map. How do I do that? – ispiro Nov 18 '19 at 21:47

1 Answers1

1

This is exactly like how the Maps app works and is what the user will expect. The behavior you're describing is completely normal; you shouldn't interfere with it.

The usual thing is that you put an MKUserTrackingButton in the interface, associated with the map view, and the user can just tap it to switch modes automatically. Except for initially configuring the button, no code is needed.

https://developer.apple.com/documentation/mapkit/mkusertrackingbutton

or

https://developer.apple.com/documentation/mapkit/mkusertrackingbarbuttonitem

matt
  • 515,959
  • 87
  • 875
  • 1,141