在android中有方法getLastKnownLocation()
,它獲取設備上最後一次獲取的更新位置。ios等同於Android中的getLastKnownLocation
重要的是,這個位置甚至不需要從您的應用程序中獲取。
我需要在IOS中做同樣的事情,所以我需要最後一次從設備獲取的位置,即使它不是來自我的應用程序(因爲我需要的位置完全不需要精確)
謝謝。
在android中有方法getLastKnownLocation()
,它獲取設備上最後一次獲取的更新位置。ios等同於Android中的getLastKnownLocation
重要的是,這個位置甚至不需要從您的應用程序中獲取。
我需要在IOS中做同樣的事情,所以我需要最後一次從設備獲取的位置,即使它不是來自我的應用程序(因爲我需要的位置完全不需要精確)
謝謝。
我解決做如下:
創建一類GpsManager,如:
@interface GpsManager : NSObject <CLLocationManagerDelegate>
@property (nonatomic, retain) CLLocationManager *locationManager;
@property (nonatomic, retain) CLLocation *location;
+(GpsManager*) getShared;
@end
,我開始它的appdelegate,這個類將保存的位置,你可以使用它,它不像android的getLastKnownLocation()那樣實用,但希望一點。
沒有全球範圍,你可以要求最後一個已知的位置。如果您的應用程序需要位置信息,那麼您的應用程序使用CLLocationManager及其委託方法就沒有其他辦法了。
注意,有一些涉及緩存,只是檢查CLLocation對象的時間戳 - 的LocationManager:didUpdateToLocation:fromLocation:
馬丁