融合地点提供意想不到的行为 [英] Fused Location Provider unexpected behavior

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

问题描述

这是我怎么注册我的应用程序,以获得位置更新:

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...

到目前为止好。

问题::当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.

另一个联合国predictable和令人不安的问题:

我为了改变 PRIORITY_BALANCED_POWER_ACCURACY PRIORITY_HIGH_ACCURACY 来看看它是如何的表现(24小时)。所有的间隔保持不变(更新之间间隔10分钟)。准确的定位,即使在手机无网络/ SIM卡确实收到,但 - 电池排出快!当我看到在电池的历史,我很惊讶地看到, GPS无线电是全传输模式所有的时间!!!! ,我也看到了我的日志网站位置收到的每一分钟,甚至我请求的位置各10分钟(我没有打开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..)

我注意到这个行为对几个设备(如极限摩托2013年,HTC One X的,的Nexus 5),全部采用最新的谷歌播放服务(6.1.11版)和Android奇巧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 模式,以prevent电池消耗。

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..

我的问题:

  • 是融合位置提供想使用GPS,如果将其设置在所有接收与 PRIORITY_BALANCED_POWER_ACCURACY 更新,没有任何Wi-Fi或蜂窝塔信息?

  • 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..

为什么GPS无线电打开所有的时间,而不是被开辟为间隔10分钟,当我使用了 PRIORITY_HIGH_ACCURACY 参数? (我没有触发位置更新快等安装的应用程序。)

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 与融合的位置提供想使用GPS,如果将其设置在所有接收与更新 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?

显然,没有一定的源文件中指定的任何地方。无论使用哪种优先级选项,甚至通过code,获得源位置是融合。
[ location.getProvider()的回报:融合]
我所看到的GPS使用,只有当 LocationRequest 有PRIORITY_HIGH_ACCURACY。所以也没有其他的条件下使用GPS。

Apparently no certain 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 为什么GPS无线电打开所有的时间,而不是被开辟为间隔10分钟,当我用PRIORITY_HIGH_ACCURACY参数? (我没有触发位置更新快等安装的应用程序。)

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分钟。按照我的理解,在<一个href="https://developer.android.com/reference/com/google/android/gms/location/LocationRequest.html#setFastestInterval(long)"相对=nofollow> setFastestInterval 给出precedence在<一个href="https://developer.android.com/reference/com/google/android/gms/location/LocationRequest.html#setInterval(long)"相对=nofollow> setInterval的的时为最快间隔的值是在更短的持续时间比的setInterval的值。
在你的情况,1票反对10
分钟 关于没有触发位置更新等安装的应用程序,它只是作为实例,而不是指定的,只有这种情况下明确。

The fastest interval has been set for 1 minute. By my understanding, 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(长)在一些快   情况下(例如,如果其它应用程序的触发位置   更新)。

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 ,它要求位置在最快的时间间隔设置 - 1分钟,用全球定位系统(一种完全)。

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..

需要检查的$ C $下 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天全站免登陆