[英]How do I get a background location update every n minutes in iOS app?
I appreciate that this question already appears to have been answered here: How do I get a background location update every n minutes in my iOS application? 我很高兴看到这里已经回答了这个问题: 如何在我的iOS应用程序中每n分钟更新一次后台位置?
However, although the solution is hinted at, I'd be really grateful if someone could post some sample code as to how this actually works. 但是,尽管暗示了解决方案,但是如果有人可以发布一些示例代码以说明其实际工作方式,我将不胜感激。
Many thanks, 非常感谢,
Jack 插口
You need to subscribe to core location during application start. 您需要在应用程序启动期间订阅核心位置。
some thing like this 像这样的东西
CLLocationManager *locationManager = [[CLLocationManager alloc] init];
locationManager.delegate = self;
locationManager.desiredAccuracy = kCLLocationAccuracyThreeKilometers;
and add delegate 并添加委托
- (void)locationManager:(CLLocationManager *)manager didUpdateToLocation:(CLLocation *)newLocation fromLocation:(CLLocation *)oldLocation
Try this one you will get the lattitude and longitude updated..in didUpdateToLocation... 试试这个,您将得到经度和纬度的更新..在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];
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.