我很欣赏这个问题似乎已经在这里得到了回答:如何在iOS应用中每n分钟更新一次后台位置?
然而,虽然解决方案是暗示的,我真的很感激如果有人可以张贴一些示例代码,这是如何实际工作的
许多谢谢,杰克您需要在应用程序启动时订阅核心位置。
像这样的
CLLocationManager *locationManager = [[CLLocationManager alloc] init];
locationManager.delegate = self;
locationManager.desiredAccuracy = kCLLocationAccuracyThreeKilometers;
和添加委托
- (void)locationManager:(CLLocationManager *)manager didUpdateToLocation:(CLLocation *)newLocation fromLocation:(CLLocation *)oldLocation
试试这个,你会得到纬度和经度更新…在didUpdateToLocation…
//in view did load
locationManager = [[CLLocationManager alloc]init];
if([CLLocationManager locationServicesEnabled])
{
locationManager.delegate = self;
locationManager.desiredAccuracy = kCLLocationAccuracyKilometer;
locationManager.distanceFilter = 1000.0f;
[locationManager startUpdatingLocation];
}
- (void)locationManager:(CLLocationManager *)manager didUpdateToLocation:(CLLocation *)newLocation fromLocation:(CLLocation *)oldLocation {
appDelegateObj.latitude= [[NSString alloc]initWithFormat:@"%g",newLocation.coordinate.latitude];
appDelegateObj.longitude = [[NSString alloc]initWithFormat:@"%g",newLocation.coordinate.longitude];
}