简体   繁体   English

Android Geofencing:仅在外部地理围栏时触发

[英]Android Geofencing: Trigger only while outside geofence

I am making a geofencing application, which must trigger notification constantly while the device is outside the geofence, not only on exit. 我正在制作一个地理围栏应用程序,它必须在设备超出地理围栏时不断触发通知,而不仅仅是在退出时。

I have tried using Geofencing API through the training example given in Google android developer training page . 我已经尝试通过Google android开发人员培训页面中提供的培训示例使用Geofencing API。 But, I got notification only when the device enters, dwell or exit. 但是,只有在设备进入,停留或退出时才会收到通知。

According to what I have researched till now in both SO and google, there are only three types of transitions handled in Geofencing API: Enter, Dwell and Exit. 根据我迄今为止在SO和Google中所研究的内容,Geofencing API中只处理了三种类型的转换:Enter,Dwell和Exit。 And the notification starts only when device enters the geofence, till it exits. 并且通知仅在设备进入地理围栏时开始,直到它退出。

Can anyone help me out how to make it work? 任何人都可以帮助我如何让它工作?

That is not possible that way. 那是不可能的。 It does not make any sense outside the geofence area. 在地理围栏区域之外没有任何意义。 That is not an usecase of geofence. 这不是地理围栏的用例。

You can try to specify broader range of the area and then check the geocoordinates if this is outside of your area you want to have. 您可以尝试指定更广泛的区域范围,然后检查地理坐标,如果它位于您想要的区域之外。

Incase you want your own custom exit trigger, when you are outside the fence. 当你在围栏外时,你想要自己的自定义退出触发器。 You can write your custom action by measuring distance (lat,long) between your current location( FusedLocationProvider ) and the fence location (lat, long). 您可以通过测量当前位置( FusedLocationProvider )和围栏位置(纬度,长度)之间的距离 (纬度,长度)来编写自定义动作。

You can use below methods available in Android Location API to measure the difference and generate a custom trigger to indicate that you are outside the fence. 您可以使用Android Location API中提供的以下方法来衡量差异并生成自定义触发器,以指示您不在围栏中。

Typically this is what you need to do 通常这是您需要做的

if[ (difference in location) > (Radius of your geo fence) ] -> Custom Exit of Fence Action if [(位置差异)>(地理围栏的半径)] - >自定义栅栏动作退出

  1. distanceTo distanceTo
  2. distanceBetween (Provide both your current lat,long and your fence lat,long here) distanceBetween (提供你当前的lat,long和你的fence lat,这里很长)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM