2015-10-10 38 views
0

我想在MapView中加載一個區域,但我總是得到整個美國的視圖。這是一個以橫向模式運行的iPad應用程序。我在想,跨度可能不是合適的尺寸,但我不知道如何解決。這是我的數據。有任何想法嗎?iOS MapView顯示整個美國

謝謝... enter image description here

回答

0

看樣子你試圖表現出用戶的位置。量程數據對於您嘗試顯示的區域看起來是正確的。

在這種情況下,在MapKit能夠顯示位置之前,位置服務需要由用戶授權。

當位置服務未被授權時,美國地圖將顯示而不是您嘗試顯示的地區。

假設您有CLLocationManager,則需要使用requestWhenInUseAuthorizationrequestAlwaysAuthorization來授權位置服務。

如果你有

self.locationManager = [CLLocationManager alloc] init]; 

,那麼你將需要調用

[self.locationManager requestWhenInUseAuthorization]; 

[self.locationManager requestAlwaysAuthorization]; 

這些都要求的NSLocationAlwaysUsageDescription一鍵添加到您的應用程序的Info.plist文件。

+0

我試圖表現出用戶的位置,但是這部分正常工作,我得到了正確的位置,藍點,但由於某種原因,沒有正確設置區域。我想知道是否可能是因爲與地圖相比,跨度不是正確的寬高比。有任何想法嗎? – SeanT

+0

@SeTT據我所知,區域顯示的兩個因素是中心和跨度。我在經緯度/經度上使用了0.001的三角洲,並且我能夠進入美國地圖的街道等級。您是否獲得了位置服務的授權?這是可以防止縮小到該地區的東西。 – Daniel

1

我已通過添加CLLocationManager解決了類似的問題:

self.locationManager = [[CLLocationManager alloc] init]; 
    self.locationManager.delegate = self; 
    // Check for iOS 8. Without this guard, the code will crash with "unknown selector" on iOS 7. 
    if ([self.locationManager respondsToSelector:@selector(requestWhenInUseAuthorization)]) { 
     [self.locationManager requestWhenInUseAuthorization]; 
    } 
    [self.locationManager startUpdatingLocation]; 
+0

我正在使用CLLocationManager,它正確顯示用戶的位置,我只是無法正確設置可見區域。 – SeanT