使用的是ipad橫屏情況下之众,移動到屏幕靠右的位置拙毫,為了保證不同縮放下移動位置不變,需要取屏幕經(jīng)緯度進行計算棺禾。如果只要移動到屏幕中心缀蹄,直接設(shè)置當(dāng)前經(jīng)緯度到屏幕中心即可。
- (void)mapView:(BMKMapView *)mapView1 didSelectAnnotationView:(BMKAnnotationView )view{
TaskPointAnnotation taskAnnotation = view.annotation;
//當(dāng)前屏幕中心點的經(jīng)緯度
float centerLongitude = mapView1.region.center.longitude;
float centerLatitude = mapView1.region.center.latitude;
//當(dāng)前屏幕顯示范圍的經(jīng)緯度
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];
}