如何在iOS中更改GPS更新时间 [英] how to change gps update time in ios

查看:149
本文介绍了如何在iOS中更改GPS更新时间的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在寻找一种方法来在我的iOS应用程序中每n分钟更新一次后台位置..现在,我每秒获取一次更新..我可以将一秒更改为三秒或四秒或每分钟吗?

I'm looking for a way to get a background location update every n minutes in my iOS application.. now i am getting update in every second.. can i change one second to three or four second or every minute...

这是我的代码:

 - (void)locationManager:(CLLocationManager *)manager didUpdateToLocation:(CLLocation *)newLocation fromLocation:(CLLocation *)oldLocation {
        if([self.delegate conformsToProtocol:@protocol(GPSLocationDelegate)]) { 
            // Check if the class assigning itself as the delegate conforms to our protocol.  If not, the message will go nowhere.  Not good.

            [self.delegate locationUpdate:newLocation];

             NSLog(@"location manager");
            /// alert for check msg ////


            ////////////////////////////
        }
    }

推荐答案

您不能这样做. 或者,您可以通过以下方式实现它.当您获得位置更新时,它将具有与之相关的时间戳.

You can not do it. Alternatively you can achieve it by below way. When you get location updates, it will have the timestamp associated with it.

在第一次位置更新时缓存时间戳.当您收到第二个位置更新时,比较差异并检查.如果它大于阈值限制,请致电您的代表,并使用更新的位置的时间戳更新缓存的时间戳.

Cache the time stamp on first location update. When you receive the second location update, compare the difference and check. If it is greater than your threshold limit, call your delegate and update the cached time stamp with updated location's time stamp.

这篇关于如何在iOS中更改GPS更新时间的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆