How to set a zoom level as 15 in the MapKit using iPhone sdk
I am implementing a MapKit based application. In that I need to set the zoom level as 15. Based on this I need to change the region. I tried with the following code but it is not working as expected. When I used the returned region and set to the Mapview it is getting exception like "NSInvalidArgumentException', reason: 'Invalid Region '".Can you guys suggest perfect way to solve this problem?
-(MKCoordinateRegion)getRegoinBasedOntheZoomLevel:(int)zoom
{
MKCoordinateRegion region;
MKCoordinateSpan span;
if (coords1.latitude != 0 && coords1.longitude !=0)
{
region.center = coor开发者_开发问答ds1;
}
else
{
region.center=mainMapView.region.center;
}
span.latitudeDelta=mainMapView.region.span.latitudeDelta *2*zoom;
span.longitudeDelta=mainMapView.region.span.longitudeDelta *2*zoom;
region.span=span;
return region;
}
Thanks in advance. Sekhar Bethalam.
Sekhar, I'm not really sure what your code is trying to achieve - it is multiplying an (unspecified) span by 2*zoom: I'm pretty sure it is not going to do what you say. 'zoom' is generally defined as a number n between 0 and N where 2^n is the number of map tiles around the earth.
Rather than try to explain the theory, see this post I found (by searching this forum) that provides an excellent overview, including hyperlinks to an excellent description of the theory and practice of Mercator projections, map tiles, and even the actual MKMapView code you need.
精彩评论