在Google关于地理围栏的教程中看不到地理围栏转换

在Google关于地理围栏的教程中看不到地理围栏转换

本文介绍了在Google关于地理围栏的教程中看不到地理围栏转换的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用 Google的示例来测试Geofence功能:监视地理围栏.我已经在此处上传了代码.

I am trying to test Geofence functionality using Google's example: Creating & Monitoring Geofences. I have uploaded the code here.

问题是我从没收到进入或退出的通知.我有Wifi,4G和GPS.我尝试通过以下方式进行测试:

Problem is that I never get a notification of entry or exit. I have Wifi, 4G and GPS on. I have tried to test in the following ways:

  1. 我什至走出家门约50英尺再走回去-但没有任何通知.我可以看到播放服务已连接,甚至" MainActivity.java中的GeofenceUtils.ACTION_GEOFENCES_ADDED"被触发,所以我认为地理围栏正在正确添加.
  2. 在设置中启用了模拟位置,并使用了伪造GPS App 并更改了位置-从与Geofence1相同的坐标开始,然后设置为完全在外部(处于另一种状态)的东西-但我仍然没有收到退出通知.
  1. I even walk out of my house for about 50ft and walk back in - but no notifications. I can see that play services gets connected and even the "GeofenceUtils.ACTION_GEOFENCES_ADDED in MainActivity.java" gets triggered, so I think Geofences are getting added correctly.
  2. Enabled Mock Locations in the Settings and used this Fake GPS App and changed location - starting from the same coordinates as the Geofence1 and then setting to something totally outside (in another state) - but I still dont get an exit notification.

我做错了什么? ANyone成功运行了 Google的示例:创建&监视地理围栏.为了方便浏览,我在此处上传了代码.

What am I doing wrong? ANyone had success in running this Google's example: Creating & Monitoring Geofences. I have uploaded the code here for easy browsing.

我只是想学习地理围栏-检测进入&出口. 我将任何答案都标记为我可以用来在我的真实设备上进行地理模拟工作的正确答案

I am just trying to learn Geofencing - detecting entry & exit. I WILL MARK ANY ANSWER AS THE RIGHT ANSWER THAT I CAN USE TO GET GEOFENCING WORKING ON MY REAL DEVICE

.

推荐答案

示例代码也有问题.我遇到的主要问题之一就是声明ReceiveTransitionsIntentService.您不需要添加BroadcastReceiver或请求位置更新,但是您需要更改AndroidManifest来将导出的值设置为true,就像这样:

I was also having issues with the example code. One of the main issues I had was around declaring the ReceiveTransitionsIntentService. You don't need to add a BroadcastReceiver or request location updates, but you need to change your AndroidManifest to set the exported value to true, like so:

<service
    android:name=".ReceiveTransitionsIntentService"
    android:exported="true" >
</service>

确保服务路径也正确.

我已经大大简化了Google示例,您可以在此处找到代码和说明.我删除了UI组件和持久性Geofence存储,因此该示例应该更容易理解.希望这会有所帮助!

I've simplified the Google example significantly and you can find the code and explanation here. I've removed the UI component and persistent Geofence storage, so this example should be easier to follow. Hope this helps!

这篇关于在Google关于地理围栏的教程中看不到地理围栏转换的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-03 00:08