If I have 3 pins in a mapview, how will I zoom to these pins, when the map loads. That is, when the map loads I need to have a zoomed view, but the view should accomodate al
you may calc the center of all pins
- (CLLocationCoordinate2D)centerPointFromAnnotationArray:(NSArray *)array
{
CLLocationCoordinate2D coorMax = CLLocationCoordinate2DMake(0, 0);
CLLocationCoordinate2D coorMin = CLLocationCoordinate2DMake(999, 999);
for ( int i = 0 ; i < [array count] ; ++i )
{
LMPoint *a = [array objectAtIndex:i];
if ( ( a.coordinate.latitude != 0.0f ) || ( a.coordinate.longitude != 0.0f ) )
{
if ( a.coordinate.latitude > coorMax.latitude )
{
coorMax.latitude = a.coordinate.latitude;
}
if ( a.coordinate.longitude > coorMax.longitude )
{
coorMax.longitude = a.coordinate.longitude;
}
if ( a.coordinate.latitude < coorMin.latitude )
{
coorMin.latitude = a.coordinate.latitude;
}
if ( a.coordinate.longitude < coorMin.longitude )
{
coorMin.longitude = a.coordinate.longitude;
}
}
}
CLLocationCoordinate2D coorCenter = CLLocationCoordinate2DMake((coorMax.latitude+coorMin.latitude)/2, (coorMax.longitude+coorMin.longitude)/2);
return coorCenter;
}
then zoom at the point with a proper zoomlevel