融合位置提供程序意外行为 [英] Fused Location Provider unexpected behavior

查看:38
本文介绍了融合位置提供程序意外行为的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是我注册我的应用以接收位置更新的方式:

this is how I register my app to receive location updates:

mLocationRequest = LocationRequest.create();
mLocationRequest.setInterval(Consts.ONE_MINUTE * 10);
mLocationRequest.setPriority(LocationRequest.PRIORITY_BALANCED_POWER_ACCURACY);
mLocationRequest.setFastestInterval(Consts.ONE_MINUTE);

Builder builder = new GoogleApiClient.Builder(context);
builder.addApi(ActivityRecognition.API);

mGoogleApiClient = builder.addConnectionCallbacks(this)
            .addOnConnectionFailedListener(this)
            .build();

mGoogleApiClient.connect();

....
....

@Override
public void onConnected(Bundle connectionHint) {
   LocationServices.FusedLocationApi.requestLocationUpdates(mGoogleApiClient, mLocationRequest, locationUpdatespendingInent);
}

我的待处理意图几乎在确切的请求间隔内在后台被调用......

my pending intent been invoked in background almost in the exact requested intervals...

到目前为止一切都很好.

so far so good.

问题:当WIFI被禁用/未连接到任何网络时,或者当没有启用3G/4G网络数据时——融合位置提供者不提供新的位置更新!!

the problem: When WIFI is disabled/ not connected to any network, or when there is no 3G/4G network data enabled - the fused location provider not providing new location updates!!

我的位置访问设置已打开,并且 GPS 卫星和 WI-FI &检查移动网络位置.

my Location access settings are turned on, and GPS satellites and WI-FI & mobile network location is checked.

更大的问题:有时在这种情况下,我确实通过挂起的意图收到位置更新回调,但使用它知道的最后一个位置(即使是一个小时前,我我早就离开那个地方几英里了)

the even bigger problem: sometimes in that case, I do receive location updates callbacks via the pending intent, but with the last location it knew (even if it was an hour ago, and I'm long long gone away miles from that place)

根据PRIORITY_BALANCED_POWER_ACCURACY的文档:

与 setPriority(int) 一起使用以请求块"级精度.块级精度被认为是大约 100 米的精度.使用这种粗略的精度通常会消耗更少的电量.

Used with setPriority(int) to request "block" level accuracy. Block level accuracy is considered to be about 100 meter accuracy. Using a coarse accuracy such as this often consumes less power.

我希望融合位置提供者在别无选择的情况下会打开 GPS,或者至少不会在没有其他选择的情况下提供新的位置更新.

I'm expecting that the fused location provider will open the GPS when it have no other choice, or at least won't provide a new location updates if he don't have any.

另一个不可预测且令人不安的问题:

我将 PRIORITY_BALANCED_POWER_ACCURACY 更改为 PRIORITY_HIGH_ACCURACY 以查看它的行为(24 小时).所有间隔保持不变(更新间隔为 10 分钟).即使在没有网络/SIM 卡的手机中也确实收到了准确的位置,但是 - 电池电量消耗很快!当我查看电池历史记录时,我惊讶地发现 GPS 无线电一直处于全传输模式!!!! 我还在我的日志中看到每分钟接收一次位置信息,甚至我每十分钟请求一次位置(我没有安装任何其他打开 GPS 接收位置的应用程序..)

I changed PRIORITY_BALANCED_POWER_ACCURACY to PRIORITY_HIGH_ACCURACY in order to see how it behaves (for 24 hours). all the intervals stayed the same (10 minutes interval between updates). accurate location indeed received even in phones with no network/sim card, but - the battery drained out fast! when I looked on the battery history, I was surprised to see that GPS radio was on full transmission mode all the time!!!! and I saw also in my log that loction was received every minute, even that I requested location each ten minutes (I don't have any other installed apps that opens GPS to receive locations..)

我在多款设备(例如 Moto X 2013、HTC One X、Nexus 5)上注意到了这种行为,所有设备均配备最新的 Google Play 服务(6.1.11 版)和 android KITKAT 4.4.4

I noticed this behavior on several devices (such as Moto X 2013, HTC One X, Nexus 5) , all with latest Google Play Services (version 6.1.11) , and android KITKAT 4.4.4

我的应用在很大程度上依赖于用户当前的位置,并且只要用户登录,就会在指定的时间间隔内定期接收位置更新,所以我不想使用 PRIORITY_HIGH_ACCURACY 模式,以防止电池耗尽..

my application depends a lot on the user current location, and periodically receives location updates in the specified interval as long as the user logged in, so I don't want to use the PRIORITY_HIGH_ACCURACY mode, to prevent battery drain..

我的问题:

  • 如果融合位置提供者设置为使用 PRIORITY_BALANCED_POWER_ACCURACY 接收更新并且没有任何 WI-FI 或手机信号塔信息,它是否会完全使用 GPS?

  • is the fused location provider suppose to use GPS at all if it set to receive updates with PRIORITY_BALANCED_POWER_ACCURACY and don't have any WI-FI or cell towers info ?

如果是这样,那我做错了什么?

if it does, then what am I doing wrong?

为什么我会收到不正确的误导性位置更新?(正如我在更大的问题"部分所解释的那样..

why I'm getting this misleading location updates that are not correct? (as I explained in the the "even bigger problem" section..

当我使用 PRIORITY_HIGH_ACCURACY 参数时,为什么 GPS 无线电一直打开,而不是每隔 10 分钟打开一次?(我没有安装其他可以更快触发位置更新的应用......)

why GPS radio is opened all the time instead of been opened for the 10 minutes interval when I used the PRIORITY_HIGH_ACCURACY parameter? (I don't have other installed apps that triggers location updates faster..)

推荐答案

对于指定的问题,

1. 是融合位置提供者,如果它设置为使用 PRIORITY_BALANCED_POWER_ACCURACY 接收更新并且没有任何 WI-FI 或手机信号塔信息?&
2. 如果是这样,那我做错了什么?

1. is the fused location provider suppose to use GPS at all if it set to receive updates with PRIORITY_BALANCED_POWER_ACCURACY and don't have any WI-FI or cell towers info ? &
2. if it does, then what am I doing wrong?

显然,文档中的任何地方都没有明确指定唯一的来源.使用任一 PRIORITY 选项,即使通过代码,获得的 location 的来源"都是融合"的.
[location.getProvider() 返回:融合"]
我见过只有在 LocationRequest 有 PRIORITY_HIGH_ACCURACY.所以在其他条件下不使用GPS.

Apparently no explicitly unique source is specified anywhere within documentation. With either PRIORITY options, even through code, the "source" of obtained location is "fused".
[location.getProvider() returns :"fused"]
I have seen GPS being used only when the LocationRequest has PRIORITY_HIGH_ACCURACY. So it does not use GPS under other conditions.

4. 为什么当我使用 PRIORITY_HIGH_ACCURACY 参数时 GPS 无线电一直打开而不是打开 10 分钟间隔?(我没有安装其他可以更快触发位置更新的应用程序..)

4. why GPS radio is opened all the time instead of been opened for the 10 minutes interval when I used the PRIORITY_HIGH_ACCURACY parameter? (I don't have other installed apps that triggers location updates faster..)

最快间隔已设置为 1 分钟.据我了解,setFastestInterval 优先于 setInterval 当最快间隔的值的持续时间比 setInterval 的值短时.
在你的情况下,1 分钟对 10.
关于没有安装其他触发位置更新的应用程序,它只是作为示例给出,并没有明确指定仅在这种情况下.

The fastest interval has been set for 1 minute. From what i understood, the setFastestInterval is given precedence over setInterval when the value for fastest interval is shorter in duration than the value of setInterval.
In your case, 1 minute against 10.
About not having other installed apps that triggers location updates, its just given as an example and not specified that only that case explicitly.

这控制了您的应用程序接收的最快速度位置更新,在某些情况下可能比 setInterval(long) 更快情况(例如,如果其他应用程序正在触发定位更新).

This controls the fastest rate at which your application will receive location updates, which might be faster than setInterval(long) in some situations (for example, if other applications are triggering location updates).

所以,PRIORITY_HIGH_ACCURACY 会发生什么,它通过使用 GPS(有点排他性)以最快的间隔集 - 1 分钟请求 location.

So, what happens is with PRIORITY_HIGH_ACCURACY, it requests location on the fastest interval set - 1min, by using GPS(kind of exclusively).

3. 为什么我会收到不正确的误导性位置更新?(正如我在更大的问题"部分所解释的那样.

3. why I'm getting this misleading location updates that are not correct? (as I explained in the the "even bigger problem" section..

还需要检查pendingIntent机制的代码.虽然可能有一些注意事项:
您可以添加 location.getTime() 确保和验证获取位置的时间.如果范围内没有 wifi 基站并且使用了 PRIORITY_BALANCED_POWER_ACCURACY,则它很可能不会更新.
第一个位置的块级精度(在调用lastKnown"时使用)无济于事.

Need to check the code for pendingIntent mechanism also. Though there could be a few things to take note of:
You can add a location.getTime() to ensure and verify the time of obtained location. Very likely it is not being updated, if there is no wifi-cell towers in range and PRIORITY_BALANCED_POWER_ACCURACY is used.
A block level accuracy of location on the first place, which is being used when "lastKnown" is called wouldn't help.

电池消耗是因为 GPS 和 1 分钟更新的组合.尝试将最快间隔设置为 5 或 10 分钟,如果这适合您的实施,但如果您需要绝对准确的位置,PRIORITY_BALANCED_POWER 可能无济于事.我通常会添加对 onLocationChanged 中获得的位置的检查,并根据它在 LocationRequest 中切换优先级.当然,它有助于一般地获取位置,除非我在没有 GPS 和 Wifi 网络视线的建筑物内.

The battery consumption was because of the combination of GPS and 1 min updates. Try setting the fastest interval as 5 or 10 mins, if that is suitable for your implementation but PRIORITY_BALANCED_POWER may not help if you need absolutely accurate location. I normally add a check for the location obtained in onLocationChanged and depending on that, switch the priority in LocationRequest. It helps in, surely, obtaining a location generally, unless i am inside a building with no line-of-sight for GPS and Wifi-Network are off.

这篇关于融合位置提供程序意外行为的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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