2014-03-26 92 views
7

要獲得最後一個已知的地理位置,我有:CLLocationManager最後已知位置

CLLocationManager * locationManager = [[CLLocationManager alloc] init]; 
CLLocation * lastKnownLocation = [locationManager location]; 

是否lastKnownLocation反映最後位置我的應用程序已經與召回或者它反映了全球的iOS系統級的最後一個單元(哪些其他應用程序或iOS可能會查詢)?

我這樣做,而不是主動查詢用戶的位置,所以我不浪費用戶的電池。

如果用戶沒有授予訪問位置權限,顯然lastKnownLocation應該爲零。我的問題特別針對用戶已授予我的應用訪問位置權限的情況。

回答

2

通常,除非您檢查其準確性和時間戳(與您的要求相比),否則通常不應簡單地依賴從location返回的現有(如果有)值。最好先啓動startUpdatingLocation,直到獲得符合您的精度要求的位置,然後選擇stopUpdatingLocation或切換至stopMonitoringSignificantLocationChanges(如果有)。

location返回的位置非常依賴於歷史記錄,因此您不能確定會以某種方式說出。你總是需要驗證你的目的的準確性。

+3

如何找出用戶在哪個城市?我只需要精確到100公里的位置數據。假設用戶至少在一個不同的應用中啓用了位置管理器至少一次,那意味着我在這裏得到了足夠的結果,對吧? 我真的很想念android的getLastKnownLocation()。 [鏈接](http://developer.android.com/reference/android/location/LocationManager.html#getLastKnownLocation(java.lang.String中))。 – stephanlindauer

相關問題