iOS 百度地图 在可视范围显示所有标注

RT :


- (void)mapViewFitAnnotations:(NSArray *)locations

{

if (locations.count < 2) return;

CLLocationCoordinate2D coor = [locations[0] 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 < locations.count; i++) {

CLLocationCoordinate2D coor = [locations[i] 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 - 0.3;

}

PS :可在改变zoomLevel时加一个是否超出最小范围的判断,转载请注明哦!

你可能感兴趣的:(iOS 百度地图 在可视范围显示所有标注)