Hi all,
I'm familiar with the Google Maps API and I'm trying to learned the iOS MapKit library now. I have an iPhone application which takes an input string and geocodes it using Google Maps geocoder service. I also want to set an appropriate zoom level for the new map but I'm not quite sure how to do it.
After reading, http://stackoverflow.com/questions/312517/determining-zoom-level-from-single-latlong-in-google-maps-api#917997
My plan was to parse the JSON response from the Google Maps API and extract the ExtendedData field.
"ExtendedData":{
"LatLonBox":{
"north":34.13919,
"south":34.067018,
"east":-118.38971,
"west":-118.442796
}
Then using that I would like to set the bounds of my map accordingly using the MapKit setRegion function.
I started laying out a function to do this, but I'm a little lost on the logic...
- (void) setMapZoomForLocation(CLLocationCoordinate2D location, double north, double south, double east, double west){
// some fancy math here....
// set map region
MKCoordinateRegion region;
region.center = location;
MKCoordinateSpan span;
// set the span so that the map bounds are correct
span.latitudeDelta = ???;
span.longitudeDelta = ???;
region.span = span;
[self.mapView setRegion:region animated:YES];
}
Alternatively, I guess I could just used the Accuracy result from a geocode result to set a sort of default zoom level. I'm just not sure how to compute the equivalent default zoom levels for the various results.
See https://code.google.com/apis/maps/documentation/geocoding/v2/#GeocodingAccuracy