Hi I am working with Maps in iPhone. Iam rotating map view with directions. Map is rotating, but not moving smoothly.
I am using below code for rotating the map. can any one tell me any suggestions for rotating map view smoothly?
float oldRad = -manager.heading.trueHeading * M_PI / 180.0f;
float newRad = -newHeading.trueHeading * M_PI / 180.0f;
CABasicAnimation *theAnimation;
theAnimation=[CABasicAnimation animationWithKeyPath:@"transform.rotation"];
theAnimation.fromValue = [NSNumber numberWithFloat:oldRad];
theAnimation.toValue=[NSNumber numberWithFloat:newRad];
theAnimation.duration = 0.5f;
[mapView setTransform:CGAffineTransformMakeRotation(newRad)];
CGPoint anchorPoint = CGPointMake(0, 0);
[[mapView annotations] enumerateObjectsUsingBlock:^(id obj, NSUInteger idx, BOOL *stop)
{
MKAnnotationView * view = [mapView viewForAnnotation:obj];
[view setTransform:CGAffineTransformMakeRotation(newRad)];
[view setCenterOffset:CGPointApplyAffineTransform(anchorPoint, CGAffineTransformMakeRotation(newRad))];
}];
In iOS 5.0 and newer, you can use
Check MKMapView’s documentation, particularly the section Tracking the User Location for more information on this.
However, if you still want to support older versions of iOS, you will have to go through all the pain of working out these glitches and bugs. I’ve done it myself (before iOS 5 was out), and believe me, you are better off with dropping support of iOS 4.