LocationManager调用onLocationChanged过于频繁? [英] LocationManager calling onLocationChanged too often?

查看:412
本文介绍了LocationManager调用onLocationChanged过于频繁?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经设置了LocationManager来获取当前位置每2分钟:

I've set up the LocationManager to get the current location every 2 minutes:

locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 120000, 0, this);

这工作正常,并onLocationChanged被称为每隔2分钟预期。然而,似乎它是被超过10-40(随机量)第二范围的每个的2分钟调用多次。我登录了onLocationChanged所以这里收到的每个位置都一些样品得到的是怎么回事的想法:

This works fine and onLocationChanged is called every 2 minutes as expected. However, it seems that it is being called multiple times over a 10-40 (a random amount) second span every 2 minutes. I log every location received in the onLocationChanged so here are some samples to get an idea of what is going on:

在17:30

GPS 32.0 50.66318929195404 10.735434293746948 0.0 2010.08.07 17:30:10
GPS 32.0 50.66315710544586 10.735423564910889 0.0 2010.08.07 17:30:14
GPS 32.0 50.66314101219177 10.735418200492859 0.0 2010.08.07 17:30:17
GPS 32.0 50.66314101219177 10.735418200492859 0.0 2010.08.07 17:30:20
GPS 24.0 50.66313564777374 10.735418200492859 0.5 2010.08.07 17:30:24
GPS 32.0 50.663098096847534 10.735573768615723 0.0 2010.08.07 17:30:28         
GPS 32.0 50.663065910339355 10.735611319541931 0.0 2010.08.07 17:30:31

然后我得到没有更多的更新2分钟。

Then I get no more updates for 2 minutes.

在17:32

GPS 32.0 50.661821365356445 10.737022161483765 1.0 2010.08.07 17:32:39
GPS 16.0 50.66170871257782 10.737043619155884 1.8200275 2010.08.07 17:32:45
GPS 24.0 50.661579966545105 10.737027525901794 1.25 2010.08.07 17:32:50
GPS 16.0 50.66150486469269 10.73712408542633 1.0 2010.08.07 17:32:55
GPS 12.0 50.661579966545105 10.73715090751648 0.9013878 2010.08.07 17:33:01
GPS 24.0 50.66139221191406 10.737038254737854 1.5811388 2010.08.07 17:33:06
GPS 16.0 50.66141366958618 10.737301111221313 0.70710677 2010.08.07 17:33:12
GPS 16.0 50.66141366958618 10.737301111221313 0.70710677 2010.08.07 17:33:12
GPS 24.0 50.661311745643616 10.737070441246033 1.118034 2010.08.07 17:33:16
GPS 16.0 50.66122591495514 10.737177729606628 1.118034 2010.08.07 17:33:22
GPS 12.0 50.66124200820923 10.737220644950867 1.3462912 2010.08.07 17:33:26
GPS 12.0 50.661311745643616 10.737268924713135 3.6055512 2010.08.07 17:33:25

等等...然后另一组的更新2分钟后的17:35。

And so on... then another set of updates 2 minutes later at 17:35.

这是标准的行为?我期待获得唯一的一个的位置,每隔2分钟,和它给了我的位置更新的时间跨度似乎相当随机的。理想情况下我会preFER只能获得一个位置......有没有办法做到这一点?

Is this the standard behavior? I was expecting to get only one location every 2 minutes, and the timespan in which it gives me location updates seems rather random. Ideally I would prefer to only get one location... is there a way to do this?

推荐答案

requestLocationUpdates的文档(字符串提供商,长minTime,浮minDistance依旧,LocationListener的监听器) concering的 minTime 参数:

From the documentation of requestLocationUpdates(String provider, long minTime, float minDistance, LocationListener listener) concering the minTime parameter:

的通知的最小时间间隔,以毫秒为单位。此字段只用作提示以节省功耗,和位置更新之间的实际时间可能比这个值更大或更小。

"the minimum time interval for notifications, in milliseconds. This field is only used as a hint to conserve power, and actual time between location updates may be greater or lesser than this value."

所以,回答您的问题,是的,这是标准的行为,不,你不能改变这一点。

So the answer to your questions, yes this is standard behavior and, no you cannot change this.

如果这对你是一个问题,如果在一定的时间内没有通过,你可以忽略调用回调方法。

If this is a problem for you, you could ignore calls to the callback method if a certain amount of time hasn't passed.

这篇关于LocationManager调用onLocationChanged过于频繁?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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