我嘗試修復地圖中幾個位置的縮放和居中。這是我用和沒有工作的代碼:爲地圖中的某些位置設置縮放和中心
MKCoordinateRegion region;
CLLocationDegrees maxLat = -90;
CLLocationDegrees maxLon = -180;
CLLocationDegrees minLat = 90;
CLLocationDegrees minLon = 180;
for(int idx = 0; idx < arrLocation.count; idx++)// here use your array or points
{
CLLocation* currentLocation = [arrLocation objectAtIndex:idx];
if(currentLocation.coordinate.latitude > maxLat)
maxLat = currentLocation.coordinate.latitude;
if(currentLocation.coordinate.latitude < minLat)
minLat = currentLocation.coordinate.latitude;
if(currentLocation.coordinate.longitude > maxLon)
maxLon = currentLocation.coordinate.longitude;
if(currentLocation.coordinate.longitude < minLon)
minLon = currentLocation.coordinate.longitude;
}
region.center.latitude = (maxLat + minLat)/2;
region.center.longitude = (maxLon + minLon)/2;
region.span.latitudeDelta = (maxLat - minLat) * 2;
region.span.longitudeDelta = (maxLon - minLon) * 2;
[mapView setRegion:region animated:YES];
我試圖在didAddAnnotationViews
和didUpdateUserLocation
,但沒有奏效。你可以幫我嗎?
我應該在哪裏使用它?什麼是arrayAnnotation?你能否提供一些關於這種方法的信息。 – Ali
arrayAnnotation是存儲所有註釋的地方,它可能在您的案例中有不同的名稱 –