1.计算所有点的经纬度范围
//向点聚合管理类中添加标注 _imageDataArr是存放经纬度标注数组
for (NSInteger i = 0; i < _imageDataArr.count; i++) {
if (i==0) {
//以第一个坐标点做初始值
_minLat = _imageDataArr[i].latitude;
_maxLat = _imageDataArr[i].latitude;
_minLon = _imageDataArr[i].longitude;
_maxLon = _imageDataArr[i].longitude;
}else{
//对比筛选出最小纬度,最大纬度;最小经度,最大经度
_minLat = MIN(_minLat, _imageDataArr[i].latitude);
_maxLat = MAX(_maxLat, _imageDataArr[i].latitude);
_minLon = MIN(_minLon, _imageDataArr[i].longitude);
_maxLon = MAX(_maxLon, _imageDataArr[i].longitude);
}
//动态的根据坐标数据的区域,来确定地图的显示中心点和缩放级别
if (_imageDataArr.count > 0) {
//计算中心点
CLLocationCoordinate2D centCoor;
centCoor.latitude = (CLLocationDegrees)((_maxLat+_minLat) * 0.5f);
centCoor.longitude = (CLLocationDegrees)((_maxLon+_minLon) * 0.5f);
BMKCoordinateSpan span;
//计算地理位置的跨度
span.latitudeDelta = _maxLat - _minLat;
span.longitudeDelta = _maxLon - _minLon;
//得出数据的坐标区域
_region = BMKCoordinateRegionMake(centCoor, span);
}
2.地图显示标注区域
/**
*地图初始化完毕时会调用此接口
*@param mapview 地图View
*/
- (void)mapViewDidFinishLoading:(BMKMapView *)mapView {
[_mapView setRegion:_region];
}
网友评论