我什么时候应该停止更新位置管理器? [英] When should I stop updating location manager?

查看:55
本文介绍了我什么时候应该停止更新位置管理器?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个可以拨打电话以获取用户位置的应用程序:

I have an app that makes a call to get the user's location:

-(void)getLocation{
    locationManager = [[CLLocationManager alloc] init];
    locationManager.delegate = self;
    locationManager.distanceFilter = kCLDistanceFilterNone;
    locationManager.desiredAccuracy = kCLLocationAccuracyBest;
    [locationManager startUpdatingLocation];

}
//SET USER LOCATION
-(void)locationManager:(CLLocationManager *)manager didUpdateLocations:(NSArray *)locations {
    self.userLocation = [locations lastObject];
    NSLog(@"location in IntroVC %f, %f", self.userLocation.coordinate.latitude, self.userLocation.coordinate.longitude);
}

我的问题是,因为NSLog不断无限地吐出新的位置,所以我什么时候应该停止呼叫该位置?好吧,我猜想它确实取决于我的应用程序的功能,但这是否会导致电池消耗?如果是这样,我应该真正研究停止更新的最佳方法.

My question is, because that NSLog keeps spitting out a new location infinitely, when should I stop calling the location? Well I guess its really up to my app's functionality, but doesnt this cause battery drain? If so, I should really look into the best way of stopping the updates.

推荐答案

位置管理器的距离"过滤器设置为kCLDistanceFilterNone.这将使didUpdateLocations方法被称为无限时间.

Your Distance filter of the location manager is set to be kCLDistanceFilterNone. This causes the didUpdateLocations method to be called infinite time.

locationManager.distanceFilter = kCLDistanceFilterNone;

将此行更改为

locationManager.distanceFilter = 10;

,然后重试.根据需要更改值.

and try again. Change the value as needed.

所以现在didUpdateLocation将不会被无限次调用. :)

So now the didUpdateLocation will not be called infinite times. :)

希望这会有所帮助.

这篇关于我什么时候应该停止更新位置管理器?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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