Hi all,
If you are adding multiple annotation in your amp and you want to show all annotations initially. then just call this method after adding all annotation to your mapview.
There are some globally declare variable such as :-
#define MINIMUM_ZOOM_ARC 0.024
#define ANNOTATION_REGION_PAD_FACTOR 1.5
#define MAX_DEGREES_ARC 360
And method to fit all annotations in map is :-
- (void)zoomMapView:(MKMapView *)mapView animated:(BOOL)animated
{
NSArray *annotations = mapView.annotations;
int count = (int)[mapView.annotations count];
if ( count == 0) { return; }
MKMapPoint points[count];
for( int i=0; i<count; i++ )
{
CLLocationCoordinate2D point = [(id <MKAnnotation>)[annotations objectAtIndex:i] coordinate];
points[i] = MKMapPointForCoordinate(point);
}
MKMapRect mapRect = [[MKPolygon polygonWithPoints:points count:count] boundingMapRect];
MKCoordinateRegion region = MKCoordinateRegionForMapRect(mapRect);
region.span.latitudeDelta *= ANNOTATION_REGION_PAD_FACTOR;
region.span.longitudeDelta *= ANNOTATION_REGION_PAD_FACTOR;
if( region.span.latitudeDelta > MAX_DEGREES_ARC ) { region.span.latitudeDelta = MAX_DEGREES_ARC; }
if( region.span.longitudeDelta > MAX_DEGREES_ARC ){ region.span.longitudeDelta = MAX_DEGREES_ARC; }
if( region.span.latitudeDelta < MINIMUM_ZOOM_ARC ) { region.span.latitudeDelta = MINIMUM_ZOOM_ARC; }
if( region.span.longitudeDelta < MINIMUM_ZOOM_ARC ) { region.span.longitudeDelta = MINIMUM_ZOOM_ARC; }
if( count == 1 )
{
region.span.latitudeDelta = MINIMUM_ZOOM_ARC;
region.span.longitudeDelta = MINIMUM_ZOOM_ARC;
}
[mapView setRegion:region animated:animated];
}
0 Comment(s)