What I want to achieve is like the animation (how the map rotates) in mapView when userTrackingMode is followWithHeading.
The thing is I can't use this tracking mode here because we draw our own blue dot based on the different location information instead of the one provided by iOS. Every time the heading get updated, I want to set the mapView's camera heading value, but animated to make it smooth.
Currently I've tried:
setCamera: animated:
This doesn't work well when the heading changes frequently.animateWithDuration:animations:completion:
This doesn't work at all.- I tried CADisplayLink like the code below, still the transition is not smooth.
CADisplayLink *timer = [CADisplayLink displayLinkWithTarget:self selector:@selector(updateHeading)];
timer.frameInterval = 5;
[timer addToRunLoop:[NSRunLoop mainRunLoop] forMode:NSDefaultRunLoopMode];
[timer addToRunLoop:[NSRunLoop mainRunLoop] forMode:UITrackingRunLoopMode];
and in the updateHeading
method I just set the mapView's camera to the current heading self.camera.heading = newHeading.trueHeading;
I guess this doesn't work because I am only setting the camera every 5/60 seconds here, it's not animating.
Can someone point out the correct way to achieve this? Any thought will be appreciated.