I have an MKMapView
and I am trying to rotate the map camera heading to follow the users heading. I don't want to do the auto-tracking because it forces a zoom level which is something I would like to have control over at the same time.
The thing is that I have found that the camera heading will revert to 0 if supplied with any value between 354 and 6 degrees. When I set the camera heading to 2 for example, it will constantly bounce between 2 and 0 until I turn the phone to a different heading.
My solution has been to just lock it to 0 when between this range but this isn't optimum. Does anyone have any information as to why this would happen? The method that gets called on heading changes looks like this:
- (void)setMapCameraPosition {
//354,6
if (self.heading <= 6 || self.heading >= 354) {
NSLog(@"****nulling heading. self.heading: %d camera.heading: %f", self.heading, self.mapView.camera.heading);
self.mapView.camera.heading = 0.0f;
}
else {
NSLog(@"changing heading. self.heading: %d camera.heading: %f", self.heading, self.mapView.camera.heading);
self.mapView.camera.heading = (double)self.heading;
}
}
If I don't have the if statement in and just set the camera to my heading, then my output ends up being:
self.heading: 357 camera.heading: -0.000000
self.heading: 357 camera.heading: -0.000000
self.heading: 357 camera.heading: -0.000000
So it seams that if I give a value that is close to north, it will auto revert to north a split second afterwards - making the map jump for forever.
How can I set the heading to a degree close to, but not actually, north without the map removing my desired heading?