如何在iOS应用中每n分钟更新一次后台位置?

时间:2011-12-02 11:41:55

标签: iphone ios core-location

我感谢此问题似乎已在此处得到解答: How do I get a background location update every n minutes in my iOS application?

然而,尽管解决方案已被暗示,但如果有人可以发布一些示例代码以了解其实际效果,我将非常感激。

非常感谢,

杰克

2 个答案:

答案 0 :(得分:0)

您需要在应用程序启动期间订阅核心位置。

像这样的事情

CLLocationManager *locationManager = [[CLLocationManager alloc] init];
locationManager.delegate = self; 
locationManager.desiredAccuracy = kCLLocationAccuracyThreeKilometers;

并添加委托

- (void)locationManager:(CLLocationManager *)manager didUpdateToLocation:(CLLocation *)newLocation fromLocation:(CLLocation *)oldLocation

答案 1 :(得分:0)

试试这个,你会得到更新的纬度和经度..在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];
  }