Reputation: 1387
How will I show all added annotation and current location blue dot together on map visible rect?
That user can see all pins and his current location when map will load without dragging the map initially. Code for ios8 and ios7.0.
I am using MKMapKit of apple.
Upvotes: 0
Views: 614
Reputation: 1849
try this
MKMapRect zoomRect = MKMapRectNull;
for (id <MKAnnotation> annotation in mapView.annotations) {
MKMapPoint annotationPoint = MKMapPointForCoordinate(annotation.coordinate);
MKMapRect pointRect = MKMapRectMake(annotationPoint.x, annotationPoint.y, 0, 0);
if (MKMapRectIsNull(zoomRect)) {
zoomRect = pointRect;
} else {
zoomRect = MKMapRectUnion(zoomRect, pointRect);
}
}
[mapView setVisibleMapRect:zoomRect animated:YES];
Upvotes: 1