[英]How To get Accurate current location in ios swift 5 meters accurate
[英]How to get location on each 200 meters in terminated state in ios
我試圖在應用程序的終止狀態下獲取用戶的位置。 我通過startMonitoringSignificantLocationChanges
執行此操作,但它在 3 公里或 5 分鍾后給出位置。 所以無法正確創建路線。 請指導我如何做到這一點。
if (_anotherLocationManager)
[_anotherLocationManager stopMonitoringSignificantLocationChanges];
self.anotherLocationManager = [[CLLocationManager alloc]init];
_anotherLocationManager.delegate = self;
_anotherLocationManager.desiredAccuracy = kCLLocationAccuracyBestForNavigation;
_anotherLocationManager.activityType = CLActivityTypeOtherNavigation;
if(IS_OS_8_OR_LATER) {
[_anotherLocationManager requestAlwaysAuthorization];
}
[_anotherLocationManager startMonitoringSignificantLocationChanges];
我自己解決了我的問題...
創建一個 locationManager 對象並像這樣分配它
self.locationManager = [[CLLocationManager alloc]init]; // initializing locationManager
_locationManager.desiredAccuracy = kCLLocationAccuracyBestForNavigation; // setting the accuracy
[self.locationManager requestAlwaysAuthorization];
if([self.locationManager respondsToSelector:@selector(allowsBackgroundLocationUpdates)]) {
[self.locationManager setAllowsBackgroundLocationUpdates: YES];
}
self.locationManager.distanceFilter = 20.0;
[self.locationManager startMonitoringSignificantLocationChanges];
self.locationManager.activityType=CLActivityTypeAutomotiveNavigation;
[self.locationManager startUpdatingLocation];
self.locationManager.pausesLocationUpdatesAutomatically = YES;
self.locationManager.delegate = self;
現在設置位置管理器委托方法。
- (void)locationManager:(CLLocationManager *)manager didUpdateToLocation:(CLLocation *)newLocation fromLocation:(CLLocation *)oldLocation {
{
if (newLocation.speed>7){
// here you got location, i settled speed 7 for my convenience.
}
if (newLocation.horizontalAccuracy <= self.locationManager.desiredAccuracy) {
//Desired location Found
[self.locationManager stopUpdatingLocation ];
}
}
你必須寫這個stopUpdatingLocation
,否則你的電池消耗會增加這么高。
使用地理圍欄來達到同樣的目的。
didExitRegion
UIApplication.LaunchOptionsKey.location
。您不會通過重要的位置監控獲得 200 米的粒度或連續跟蹤。
您是否在文檔中看到過這些注釋:
顯着變化位置服務僅在設備位置發生顯着變化(例如 500 米或更遠)時才提供更新。
如果 GPS 級別的精度對您的應用程序並不重要,並且您不需要持續跟蹤,則可以使用重大變化位置服務。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.