[英]Different map zoom on iPhone 4 and iPhone 5
我正在為我的項目使用MapKit
,到目前為止,它一直很好。 這是我用於顯示和居中地圖的代碼段。
CLLocation *locSouthWest = [[CLLocation alloc] initWithLatitude:southWest.latitude longitude:southWest.longitude];
CLLocation *locNorthEast = [[CLLocation alloc] initWithLatitude:northEast.latitude longitude:northEast.longitude];
CLLocationDistance meters = [locSouthWest distanceFromLocation:locNorthEast];
MKCoordinateRegion region;
region.center.latitude = (southWest.latitude + northEast.latitude) / 2.0;
region.center.longitude = (southWest.longitude + northEast.longitude) / 2.0;
region.span.latitudeDelta = meters / 111319.5;
region.span.longitudeDelta = 0.0;
[self.mapView setRegion:region animated:YES];
問題是,它在iPhone 4和iPhone 5上的工作方式不同 。
這是iPhone 4 ( iOS5和iOS6的結果相同 ):
這是iPhone 5 (使用相同的坐標):
有人遇到同樣的事情嗎?
這些是導致差異的代碼行:
region.center.latitude = (southWest.latitude + northEast.latitude) / 2.0;
region.center.longitude = (southWest.longitude + northEast.longitude) / 2.0;
由於屏幕尺寸不同,它們必然會產生差異。
您可以在此處使地圖居中的方法是使用mapView.centerCoordinate
MapKit具有固定的縮放級別。 設置地圖的區域可確保該區域在地圖中可見,但不會設置確切的縮放比例。 這有很多好處,主要的好處是您無法創建不成比例縮放緯度和經度的地圖(導致混亂和/或誤導的地圖)。 地圖的框架大小不同,因此您選擇的區域可以在每個設備上以不同的縮放級別顯示。
作為實驗,請嘗試在兩個設備上將地圖視圖的框架設置為相同的大小。 然后,如果您絕對需要地圖以相同的比例顯示,則可以進行一些數學運算以根據地圖的框架計算適當的區域。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.