简体   繁体   中英

How to show current location and all annotation pin on map together iOS 8

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.

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];

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM