4

I've been logging the altitude of an MKMapView's camera as the view is scrolled and I've discovered a strange behavior: the altitude of the viewpoint fluctuates as the user scrolls although the apperance of the map's zoom level stays the same.

After closer inspection, it seems that the altitude decreases as the user scrolls South (toward the equator) and the increases again once the user passes the equator. I thought that it might have something to do with curvature of the Earth and possible involve some trigonometry or cartography knowledge that I don't have.

I am trying to emulate this function. I have a CLLocationCoordinate2D and the current altitude and zoom level and I want to calculate the proper altitude for the MKMapCamera.

Thanks!

Matt
  • 1,359
  • 18
  • 22

1 Answers1

5

I found your post when asking the same question. I then found this post:

How to determine the correct altitude for an MKMapCamera focusing on an MKPolygon

Condensing this into the answer to your question (and mine):

    double distance = MKMetersBetweenMapPoints(MKMapPointForCoordinate(pinCenter.coordinate),
                                               MKMapPointForCoordinate(pinEye.coordinate));
    double altitude = distance / tan(M_PI*(15/180.0));

    MKMapCamera *camera = [MKMapCamera cameraLookingAtCenterCoordinate:pinCenter.coordinate
                                                     fromEyeCoordinate:pinEye.coordinate
                                                           eyeAltitude:altitude];
Community
  • 1
  • 1
smallwisdom
  • 191
  • 6