2012-10-28 25 views
0

我有一個應用程序,在啓動中心的特定位置。ios6 visibleMapRect不正確

//Calculate and set new center point 
CLLocationCoordinate2D zoomLocation = CLLocationCoordinate2DMake(<some lat>,<some long>); 

MKCoordinateSpan span; 
span.latitudeDelta = 0.08; 
span.longitudeDelta = 0.08; 

//MKCoordinateRegion region = MKCoordinateRegionMake(zoomLocation, span); 
MKCoordinateRegion region = [mapView regionThatFits:MKCoordinateRegionMake(zoomLocation, span)]; 

[mapView setRegion:region animated:YES]; 
[self refreshMap]; 

到refreshMap呼叫嘗試計算地圖的邊框,這樣我可以查詢到數據庫中的相應信息。

//Calculate map's bounding box 
MKMapRect mapRect = [mapView visibleMapRect]; 

MKMapPoint cornerPointNE = MKMapPointMake(MKMapRectGetMaxX(mapRect), mapRect.origin.y); 
CLLocationCoordinate2D upperLeft = MKCoordinateForMapPoint(cornerPointNE); 

MKMapPoint cornerPointSW = MKMapPointMake(mapRect.origin.x, MKMapRectGetMaxY(mapRect)); 
CLLocationCoordinate2D lowerRight = MKCoordinateForMapPoint(cornerPointSW); 

if(fabs(upperLeft.longitude) > 80.00 || fabs(lowerRight.longitude) > 80.0) { 
    return; 
} 

的問題,我看到的是,在iOS 6中的lowerRight協調在應用程序啓動和地圖數據沒有得到刷新爲lowerRight.longitude是> 80.0計算不正確。 upperLeft被正確計算。

在應用程序加載完成後,如果我平移地圖,即使邊界框的邊界計算是正確的。

此代碼工作正常的iOS 5

有回調比MapView的其他:regionDidChangeAnimated,我可以用? refreshMap的其餘部分相當密集,我不想影響平移性能。

TIA

UPDATE

我似乎已經找到了解決。相反,這樣做

[mapView setRegion:region animated:YES]; 

的我改變了YES爲NO

[mapView setRegion:region animated:NO]; 

現在的下角被正確應用程序啓動時計算。

+1

由於經度範圍是-180到180(緯度必須從-90到90),因此好奇爲什麼代碼檢查經度是否大於80。 – Anna

+0

它只是檢查經度大於80,因爲我只關心美國的某個州不跨越這條線。這是防止整個數據庫被從這樣荒謬的高度查詢和顯示的一種方式。 –

回答

1

您是否使用MKMapRectOffset或Inset稍微移動可見矩形。

此外,我不斷重新讀你的問題,我可能是錯的;但是,我認爲東北角是右上角,西南角是左下角。而你會想要NW和SE的角落。

我一直無法在Map Kit參考中確認mapRect的原點位於左上角。

+0

是的,我可能會倒退變量名稱......我只是看着那個。我會研究你的建議。謝謝! –