1

I am trying to rotate a map view in my app according the the user's current route. (I don't like to use the built in compasse because only 3GS uses it and it suffers too much interference from other machines, i.e. your own car.).

the CGAffineTransformMakeRotation method will rotate the Whole Map View, so the Google Logo will not be in the lower right of the screen anymore. Also all Annotation Views will rotate and look weird on the App.

Does anyone knows how to rotate just the content (streets drwaings) of the MkMapView?

Thanks

user223814
  • 51
  • 2
  • 6

1 Answers1

2

Here is how I'm rotating the MapView (see Rotate MapView using Compass orientation):

[self.mapView setTransform:CGAffineTransformMakeRotation(-1 * currentHeading.magneticHeading * 3.14159 / 180)];

Then to keep the orientation of the annotation views with the top of the device:

for (MKAnnotation *annotation in self.mapView.annotations) {
     MKAnnotationView *annotationView = [self.mapView viewForAnnotation:annotation]; 
     [annotationView setTransform:CGAffineTransformMakeRotation(currentHeading.magneticHeading * 3.14159 / 180)];
}

If you want the point of rotation of the annotationViews to be say the bottom center, I believe you would set each view's anchorPoint as follows:

  annotationView.layer.anchorPoint = CGPointMake(0.5, 1.0);

I'm still having some issues with the annotationView position changing when I do this though (probably same problem as stackoverflow question: changing-my-calayers-anchorpoint-moves-the-view).

Community
  • 1
  • 1
rockfakie
  • 2,330
  • 3
  • 17
  • 9
  • 1
    I'm doing a similar thing for rotating a MapView according to the heading information retreived by CoreLocation. I released it under MIT at github (also includes more useful stuff like a BarButtonItem that behaves like the one of the built-in Google Maps App) - https://github.com/myell0w/MTLocation – myell0w Mar 06 '11 at 13:59
  • try to use newHeading variable inside of the didUpdateHeading:(CLHeading *)newHeading handler – fyasar Jun 07 '11 at 08:26