I have a MKMapView that I am trying to rotate around the bottom center of itself. I have a simple method that gets the users magnetometer heading and changes the camera view of the map to the heading, this works just fine.
My problem though is setting the anchor point on the map in lat/long that the map will rotate around. I can get set my desired point to be the bottom of my map with this method:
-(void)setMapCenterFromLocation:(CLLocationCoordinate2D)location {
MKCoordinateRegion oldRegion = [self.mapView regionThatFits:MKCoordinateRegionMakeWithDistance(location, 10000, 10000)];
CLLocationCoordinate2D centerPointOfOldRegion = oldRegion.center;
CLLocationCoordinate2D centerPointOfNewRegion = CLLocationCoordinate2DMake(centerPointOfOldRegion.latitude + oldRegion.span.latitudeDelta / 2.0, centerPointOfOldRegion.longitude);
MKCoordinateRegion newRegion = MKCoordinateRegionMake(centerPointOfNewRegion, oldRegion.span);
[self.mapView setRegion:newRegion animated:YES];
}
And I can rotate the map with:
- (void)magneticDirectionChanged:(NSNotification *)notification {
CLHeading *heading = (CLHeading *)[[notification userInfo] valueForKey:@"heading"];
CLLocationDirection newDirection = heading.trueHeading;
self.currentHeading = (int)newDirection;
[self.mapView.camera setHeading:self.currentHeading];
}
But the rotation happens around the center of the map, not the bottom center point that I wanted. Even if I call setMapCenterFromLocation: after doing the rotation, it still counts it as looking from north and thus it goes off to the sides of the map.
How do I keep a specific point on the bottom center of the map while programmatically rotating the map / resizing the map?
Edit: A solution I suppose would be to double the height of the map and then hide the bottom half of the map from being visible. How could this be accomplished?