IOS: mapkit scaling for two annotation points

I want to know if there is a way to have dynamic scaling when I set the blue dot (my position) in my map view and another output ... when I load mapview, I want to show these two points in the same frame ... maybe ? thanks

+6
source share
1 answer

Yes it is possible. After adding the second annotation. This sample code should work for any number of annotations:

MKMapRect zoomRect = MKMapRectNull; NSArray *annotations = [mapView annotations]; for (MKAnnotation *annotation in 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]; 
+8
source

Source: https://habr.com/ru/post/916050/


All Articles