Setting MKMapView zoom level to locality
I want to set the zoom level (OR set region) of MKMapView so that I can show the terrain. Let's develop my context with an example. I have a location (CLLocation *) from which I learned the terrain using CLGeocoder (reverse geocoding). Now, let's say the area is the Cupertino, California area. How do I find an area that fully covers Cupertino in MKMapView?
Thank.
source to share
Create an object MKCoordinateRegion
and set the map display area for this:
CLLocationCoordinate2D location = CLLocationCoordinate2DMake(<LATITUDE>, <LONGITUDE>);
MKCoordinateRegion region;
// <LATITUDE> and <LONGITUDE> for Cupertino, CA.
region = MKCoordinateRegionMake(location, MKCoordinateSpanMake(0.5, 0.5));
// 0.5 is spanning value for region, make change if you feel to adjust bit more
MKCoordinateRegion adjustedRegion = [self.mapView regionThatFits:region];
[self.mapView setRegion:adjustedRegion animated:YES];
Edit:
As you pointed out in your comment, you need a dynamic city building. In this case, we need the scale of the map scaling (integer value - by default - 0).
That means some API or web service that returns city / coordinates and zoom level. So from this zoom level we can achieve a map range / area calculation.
And a link to get the zoom level from lat / long: http://troybrant.net/blog/2010/01/set-the-zoom-level-of-an-mkmapview/
source to share