Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Rotation MKMapView without Upside-Down Labels

UPDATE

Apple fixed this is iOS 7. More info after public launch.


So, I have this bit of code:

- (void)locationManager:(CLLocationManager *)manager didUpdateHeading:(CLHeading *)newHeading
{
    CGAffineTransform transform = CGAffineTransformMakeRotation(degToRad([newHeading trueHeading]));
    [mapView setTransform: transform];
}

Which beautifully renders directionally rotated map, like so:

enter image description here

Problem is, the labels are all upside down. Now, I'm pretty sure one can work around this, because I believe Apple touted the ability to rotate labels in an iOS 6 keynote. I'm just not seeing how.

For comparison, the effect I'd like, as implemented in the stock Maps app:

enter image description here

TL;DR

How do I rotate the map, but keep the labels right-side up? Or at least rotate the labels independently of the map?

like image 262
Patrick Perini Avatar asked Feb 24 '26 17:02

Patrick Perini


1 Answers

Applying a transformation onto the map is not the correct way to apply user heading rotations. Metaphorically speaking you're rotating the entire canvas instead of the elements on the canvas.

What you want to do is to call: [mapView setUserTrackingMode:MKUserTrackingModeFollowWithHeading animated:YES]; (for instance in your viewDid/WillAppear method or some IBAction trigger method.

You can read more about it here: http://developer.apple.com/library/ios/documentation/MapKit/Reference/MKMapView_Class/MKMapView/MKMapView.html#//apple_ref/occ/instm/MKMapView/setUserTrackingMode:animated:

By calling above method you tell the map view to start updating the heading (rotation). Label rotations will then adjust automagically.

like image 183
pkluz Avatar answered Feb 26 '26 07:02

pkluz



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!