其他技術(shù)文檔提供的也是可以的,不過存在一個邊點問題,也就是說一個點剛好在屏幕的邊緣,不符合需求 ,話不多說,直接上代碼
- (BMKCoordinateRegion)getCoordinateRegionWithPoints:(NSArray <CLLocation *>*)points{
double minLat = 90.0;
double maxLat = -90.0;
double minLon = 180.0;
double maxLon = -180.0;
for (size_t i = 0; i < points.count; i++) {
minLat = fmin(minLat, ((CLLocation *)points[i]).coordinate.latitude );
maxLat = fmax(maxLat,((CLLocation *)points[i]).coordinate.latitude);
minLon = fmin(minLon, ((CLLocation *)points[i]).coordinate.longitude);
maxLon = fmax(maxLon, ((CLLocation *)points[i]).coordinate.longitude);
}
CLLocationCoordinate2D center = CLLocationCoordinate2DMake((minLat + maxLat) * 0.5, (minLon + maxLon) * 0.5);
CLLocationDegrees latDiff = (center.latitude - minLat) * 2.0;
CLLocationDegrees longDiff = (center.longitude - minLon) * 2.0;
BMKCoordinateSpan span = {fabs(latDiff)+0.05,fabs(longDiff)+0.05};
BMKCoordinateRegion region = {center, span};
return region;
}
最主要的設(shè)置
BMKCoordinateSpan span = {fabs(latDiff)+0.05,fabs(longDiff)+0.05};
0.05 是你需要調(diào)整的
效果如下

WeChat435ba93f6687b9607303f173d4965aff.png
喜歡的話,點個關(guān)注