Search code examples
iphoneobjective-cdictionaryzooming

MapKit iPhone display Zoom Controls


Is it possible using MapKit to show a map in iPhone, like i´m doing, to display zoom controls on the map?

If not, what are the flags or methods i should use to increase and diminish the zoom, so i can created methods which will do this at the push of a button.


Solution

  • There aren't any built-in controls for it.

    A couple of suggestions:

    1. You can predefine some spans and store them in an array somewhere and then store your position in that array as well. Zooming in/out changes the position and gets the span.
    2. Zooming in takes the current span and divides by 2, zooming out multiplies by 2.

    You change the span in the region of the mapView. So you have to:

    • Get the region of the mapView.
    • Get the span of the region.
    • Change the span to what you want.
    • Set the regions span to the new span.
    • Set the mapView's region to the new region.

    Here's some code for suggestion 2:

    MKCoordinateRegion region = mapView.region;
    MKCoordinateSpan span;
    span.latitudeDelta = region.span.latitudeDelta*2;
    span.longitudeDelta = region.span.longitudeDelta*2;
    region.span = span;
    [mapView setRegion:region animated:TRUE];