百度地图calloutview位置自动移动

使用的是ipad横屏情况下,移动到屏幕靠右的位置,为了保证不同缩放下移动位置不变,需要取屏幕经纬度进行计算。如果只要移动到屏幕中心,直接设置当前经纬度到屏幕中心即可。
- (void)mapView:(BMKMapView *)mapView1 didSelectAnnotationView:(BMKAnnotationView )view{
TaskPointAnnotation
taskAnnotation = view.annotation;

//当前屏幕中心点的经纬度
float centerLongitude = mapView1.region.center.longitude;
float centerLatitude = mapView1.region.center.latitude;
//当前屏幕显示范围的经纬度
CLLocationDegrees pointssLongitudeDelta = mapView1.region.span.longitudeDelta;
CLLocationDegrees pointssLatitudeDelta = mapView1.region.span.latitudeDelta;
//左上角
float leftUpLong = (centerLongitude - pointssLongitudeDelta/2.0);
float leftUpLati = (centerLatitude + pointssLatitudeDelta/2.0);
//右上角
float rightUpLong = (centerLongitude + pointssLongitudeDelta/2.0);
float rightUpLati = (centerLatitude + pointssLatitudeDelta/2.0);
//左下角
float leftDownLong = (centerLongitude - pointssLongitudeDelta/2.0);
float leftDownlati = (centerLatitude - pointssLatitudeDelta/2.0);
//右下角
float rightDownLong = (centerLongitude + pointssLongitudeDelta/2.0);
float rightDownLati = (centerLatitude - pointssLatitudeDelta/2.0);
NSLog(@"\n 左上   %f,%f\n 右上   %f,%f\n 左下  %f,%f \n 右下  %f,%f",leftUpLong,leftUpLati,rightUpLong,rightUpLati,leftDownLong,leftDownlati,rightDownLong,rightDownLati);

//保证在不同缩放比例下calloutView显示位置正常
float LongOffset = (rightUpLong - leftUpLong)/7;
CLLocationCoordinate2D coordinate;
coordinate.latitude = taskAnnotation.coordinate.latitude;
coordinate.longitude = taskAnnotation.coordinate.longitude-LongOffset;
[mapView setCenterCoordinate:coordinate animated:YES];
}

你可能感兴趣的:(百度地图calloutview位置自动移动)