简体   繁体   English

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

[英]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.

相关问题 应用程序进入后台后每n分钟获取用户位置 - Getting user location every n minutes after app goes to background 即使用户覆盖50米,当应用程序未在ios10的后台运行(暂停)时,如何每隔n秒获取当前的GPS位置? - How can I get current GPS location in every n seconds when app is not running in background (suspended) for ios10 even if user covers 50 meters? 每隔N分钟在后台迅速将位置发送到服务器 - Send the location to the server every n minutes in the background in swift 如何在iOS中每n秒获取位置更新 - how to get location updates for every n secs in ios 即使应用程序在后台运行,如何使用swift在ios中获取位置更新 - How to get location update in ios using swift even when the app is running in background 如何在 iOS 中每 5 分钟在后台执行一次请求 - How to do a request in background each 5 minutes in iOS 在后台模式下,如何在iOS5上获取用户位置? - How to get user location on iOS5 while app in background mode? 如何在推送通知触发的情况下在后台捕获iOS位置? - How do I capture iOS location in the background, triggered by a push notification? iOS:如何在应用程序中进行I18N /本地化? - iOS: How to do I18N/Localization in-app? 如何在iPhone的背景模式下获取当前位置? - How do i get the current location in the background mode in iPhone?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM