地理栅栏不能按预期工作 [英] Geofences do not work as expected

查看:144
本文介绍了地理栅栏不能按预期工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在github上创建和监控Geofences示例应用不会按预期工作,Google Play服务中的Geofences似乎无法正常工作。

我在Stack Overflow的其他地方看过,Reto Meier在Google IO上提到GPS只有在手机靠近地理围栏以节省电池时才会打开。
似乎根本没有开启。



以下是情况:


  • 我有一个带有Google API的仿真器(与真实手机相同)。
  • >
  • 我有一个KML文件,它驱使我进出Geofence。


Gofence ENTER是 not 触发。



现在,为了确保KML真正起作用,我打开了Google地图。我玩KML,我可以看到蓝色的你在这里,很好地进出Geofence,地理栏位 do 被触发。



当Google地图启动并运行时,我在状态栏中看到GPS指示器。

因此,在我看来,Goefence只有在GPS明确开启时才会触发。



有人可以解释一下吗? Stack Overflow处理同样的问题有很多问题。



谢谢。



编辑
是否使用真实手机进行了现场测试。虽然位置更新应用程序正在运行并跟踪我创建和监控Geofences示例应用程序正在获取ENTER / EXIT事件。只要我杀了位置更新应用程序,Geofences应用程序就停止了进入/退出事件。



对我来说,Google似乎已经优化了Geofences的功耗,无用。

解决方案

我找到了解决方案。这是一种滥用,但这是让Geofence有用的唯一方法。



我需要做的是请求位置更新:

  mLocationRequest = new LocationRequest(); 
mLocationRequest.setInterval(10000);
mLocationRequest.setFastestInterval(5000);
mLocationRequest.setPriority(LocationRequest.PRIORITY_HIGH_ACCURACY);
LocationServices.FusedLocationApi.requestLocationUpdates(
mGoogleApiClient,mLocationRequest,mGeofencePendingIntent);

现在我们可以注册地理围栏。



这里是我的理解为什么上述工作:
根据 documentation
如果您的应用程序想被动地观察由其他应用程序触发的位置更新,但不会消耗任何额外的权力,否则,然后使用PASSIVE_PROVIDER此提供程序不会主动打开或修改活动位置提供程序



在我看来,添加地理围栏是PASSIVE_PROVIDERS。这可以解释为什么在Google地图打开时触发地理栅栏。



当然,我们可以使用 PRIORITY_BALANCED_POWER_ACCURACY 而非HIGH()以保留一些电池,并且在我们放置地理围栏时和使用多长时间时保持智能。


Creating and Monitoring Geofences example app on github does not work as expected, Geofences in Google Play Services don't seem to work properly.

I have read elsewhere at Stack Overflow, that Reto Meier mentioned at Google IO that the GPS will turn on only if the phone approaches the geofence to conserve battery. Seems that it does not turn on at all.

Here is the situation:

  • I have an Emulator with Google APIs (same happens with real phone).
  • I have the above mentioned app out of the box installed and Geofence added.
  • I have a KML file that drives me in and out of the Geofence.

Gofence ENTER is not triggered.

Now, just to be sure that KML actually works, I open Google maps. I play KML and I can see the blue "You Are Here" dot nicely moving in and out of Geofence, and the geofences do get triggered.

While Google Maps is up and running, I see GPS indicator in status bar.

So, it seems to me that Goefence only gets triggered if the GPS is explicitly on.

Can somebody explain this please? There is a lot of questions here on Stack Overflow that deal with the same problem.

Thanks.

EDIT: Did the field test with real phone. While Location Updates app was running and tracking me Creating and Monitoring Geofences example app was getting ENTER/EXIT events. As soon as I killed Location Updates app, the Geofences app stopped getting ENTER/EXIT events.

Seems to me like Google has optimized the power consumption for Geofences to the point of uselessness.

解决方案

I found the solution. It's an abuse, but that's the only way to get Geofence useful.

All I need to do is request location updates:

mLocationRequest = new LocationRequest();
mLocationRequest.setInterval(10000);
mLocationRequest.setFastestInterval(5000);
mLocationRequest.setPriority(LocationRequest.PRIORITY_HIGH_ACCURACY);
LocationServices.FusedLocationApi.requestLocationUpdates(
            mGoogleApiClient, mLocationRequest, mGeofencePendingIntent);

And now we can register geofences.

Here is my understanding why the above works: According to documentation: "If your application wants to passively observe location updates triggered by other applications, but not consume any additional power otherwise, then use the PASSIVE_PROVIDER This provider does not actively turn on or modify active location providers"

Seems to me that added geofence is one of PASSIVE_PROVIDERS. That would explain why geofence got triggered when Google Maps was open.

Of course, we could use PRIORITY_BALANCED_POWER_ACCURACY instead of HIGH (~40m accuracy) to preserve some battery and be smart about when we put geofence on and for how long.

这篇关于地理栅栏不能按预期工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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