Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Setting MKUserTrackingModeFollowWithHeading

Tags:

ios5

I tried to set the user tracking mode in the viewDidLoad method (and in viewWillAppear). If I set it to MKUserTrackingModeFollowWithHeading (value of 2), it does not take effect. Actually, right after setting its value to 2, if I print it value, it is 1, why? I have never seen such a thing in any programming experience!

Here is how I set it:

[self.mapView setUserTrackingMode: MKUserTrackingModeFollowWithHeading 
                         animated: YES];

If I do the same in the viewWillAppear method, the effect is the same. However, the second time this view is displayed, the setting will take effect. (I have a tab viewcontroller, I switch the view to another and then switch back).

The way I see it does not take effect is two measures: (1) print its value right after setting it (2) in the map view, the heading is not displayed.

What the is going on?

like image 852
user1020156 Avatar asked Oct 29 '11 21:10

user1020156


2 Answers

I know this is a really old post, but just in case it helps others out there looking for a solution, the reason is because you need to set the userTrackingMode after the map has loaded. So set your class as the delegate, then add this delegate method:

- (void)mapViewDidFinishLoadingMap:(MKMapView *)mapView {
    mapView.userTrackingMode = MKUserTrackingModeFollowWithHeading;
}
like image 114
Daniel Avatar answered Oct 22 '22 19:10

Daniel


I also have the same issue. Cannot find any information in the map header about it not working, or working for that matter.

The solution I've implemented is to use a custom CLLocationManager to retrieve the heading, and then rotate the map appropriately. See this answer for some help using this method: Rotate MapView using Compass orientation

Also note that the iOS simulator doesn't currently allow for heading simulation.

like image 39
mm282 Avatar answered Oct 22 '22 17:10

mm282