0
我想多次更新當前位置。 在我viewDidLoad方法:更新多次當前位置
locationManager = [[CLLocationManager alloc] init];
locationManager.desiredAccuracy = kCLLocationAccuracyBest;
locationManager.delegate = self;
locationManager.distanceFilter = 1000.0f;
if ([[[UIDevice currentDevice] systemVersion] floatValue] >= 8.0){
[locationManager requestWhenInUseAuthorization];
}
[locationManager startUpdatingLocation];
在我didUpdateToLocation方法我已經登錄newlocation。
-(void)locationManager:(CLLocationManager *)manager
didUpdateToLocation:(CLLocation *)newLocation
fromLocation:(CLLocation *)oldLocation
{
latitude = newLocation.coordinate.latitude;
longitude = newLocation.coordinate.longitude;
NSLog(@"Updated Location : lat--%f long--%f",latitude,longitude);
}
但它只記錄一個。
我想更新當前多次。
====更新我的代碼:
-(void)getCurrentLocation{
locationManager = [CLLocationManager new];
locationManager.delegate = self;
locationManager.distanceFilter = kCLDistanceFilterNone;
locationManager.desiredAccuracy = kCLLocationAccuracyBest;
[locationManager startUpdatingLocation];
}
- (void)locationManager:(CLLocationManager *)manager
didUpdateLocations:(NSArray *)locations {
// If it's a relatively recent event, turn off updates to save power.
CLLocation* location = [locations lastObject];
// NSDate* eventDate = location.timestamp;
// NSTimeInterval howRecent = [eventDate timeIntervalSinceNow];
// if (abs(howRecent) < 15.0) {
// If the event is recent, do something with it.
longitude = location.coordinate.longitude;
latitude = location.coordinate.latitude;
[_lbllongtitude setText:[NSString stringWithFormat:@"%+.6f",longitude]];
[_lbllatitude setText:[NSString stringWithFormat:@"%+.6f",latitude]];
// }
[self getLocationMapView];
}
它不是自動更新當前的位置,
請幫幫我!
無關,但從來沒有做iOS版本檢查。檢查是否存在類或方法。 – rmaddy
該委託方法也被棄用 - 使用'didUpdateLocations:'您是否從最初位置移動了一公里以上? – Paulw11
使用 - (void)locationManager:(CLLocationManager *)manager didUpdateLocations:(NSArray *)locations方法。 Paulw11你能幫我解決一下這個問題嗎? – user5068763