Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Experience with MKMapView Rotation

I have an MKMapView that I am considering rotating in order to more conveniently display a series of Annotations to my users.

As of now I am planning on simply rotating the entire view with a CGAffineTransform, but I wanted to know if anyone had any experience with MKMapView rotation.

  • Are there any pitfalls or "gotchas" that you came across when adding rotation?
  • Is there an easier way to rotate a mapview?
  • If I have an overlay will the convertCoordinate:toPointToView: method still work the same way? I would assume that I'd have to apply the same transform to my overlay for the points to line up, but maybe the method is smarter than that.

If there's anything that you think could help out I'd love to hear it all.


Edit: After much experimentation I believe that I'll be using static maps that I can rotate and overlay myself, however, I would still be interested in any information about MKMapView rotation.

like image 937
jessecurry Avatar asked Oct 05 '09 23:10

jessecurry


4 Answers

I also plan to use rotated MKMapView in my application. To show annotations unrotated I use the following code:

- (MKAnnotationView *)mapView:(MKMapView *)mapView viewForAnnotation:(id <MKAnnotation>)annotation{
    ...
    annotationView.transform = GAffineTransformInvert(mapView.transform);
    ...
}

It seems to work for me.

like image 200
Vladimir Avatar answered Nov 07 '22 18:11

Vladimir


Sorry to revive a finished topic, but one more 'gotcha': if you size your map view to be large enough to rotate so that it always covers the entire screen then you'll end up cropping the 'Google' logo from the bottom left. This is explicitly contrary to the licence under which you use MapKit and may be grounds for an app rejection. In practice, adding a static version of the Google logo as a UIImageView on top seems to be considered acceptable by all parties.

like image 39
Tommy Avatar answered Nov 07 '22 17:11

Tommy


That's a fresh sample of MKMapView rotation with iPhone ccelerometer. Hope it'll help.

like image 43
slatvick Avatar answered Nov 07 '22 17:11

slatvick


I started working with MKMapView rotations and have found that:

  • When you apply a CGAffineTransform to the map view the method convertCoordinate:toPointToView: works the same.
  • Annotations rotate with the view, including annotation text.
  • Region that fits still appears to fit to a region on the screen, it doesn't fit to the map view (I made my map view larger than its parent view so it could rotate without showing the view behind).
like image 33
jessecurry Avatar answered Nov 07 '22 17:11

jessecurry