使用的是百度地图SDK
导入头文件#import <BaiduMapAPI_Utils/BMKUtilsComponent.h>
[_mapView showAnnotations:tempArr animated:YES];
[self mapViewFitAnnotations:tempArr];
-
(void)mapViewFitAnnotations:(NSArray *)annotations
{
if (annotations.count < 2) return;BMKPointAnnotation *annotation = annotations[0];
CLLocationCoordinate2D coor = annotation.coordinate;
BMKMapPoint pt = BMKMapPointForCoordinate(coor);CGFloat ltX, ltY, rbX, rbY;
ltX = pt.x;
ltY = pt.y;
rbX = pt.x;
rbY = pt.y;for (int i = 1; i < annotations.count; i++) {
BMKPointAnnotation *annotation = annotations[i];
CLLocationCoordinate2D coor = annotation.coordinate;
BMKMapPoint pt = BMKMapPointForCoordinate(coor);
if (pt.x < ltX) ltX = pt.x;
if (pt.x > rbX) rbX = pt.x;
if (pt.y > ltY) ltY = pt.y;
if (pt.y < rbY) rbY = pt.y;
}
BMKMapRect rect;
rect.origin = BMKMapPointMake(ltX , ltY);
rect.size = BMKMapSizeMake(rbX - ltX, rbY - ltY);
[_mapView setVisibleMapRect:rect];
_mapView.zoomLevel = _mapView.zoomLevel - 2;
}