Android: Build Polygonal Shape Geofence

妖精的绣舞 提交于 2019-11-26 18:29:29

问题


According to the API documentation, only Circular shape Geofences allowed:

https://developers.google.com/android/reference/com/google/android/gms/location/Geofence.Builder

And it's looks for example: https://developer.android.com/training/location/geofencing.html

But I have 4 locations, representing 4 corners of rectangle, and I want my Geofence to be that rectangle.

I want to avoid solution of building my custom location monitoring service extending the functionality of monitoring Geofences, because I think this kind of services are CPU & power consuming...

Thanks,


回答1:


You have to do it by yourself (however I think it's rather senseless - geofences/location services are inaccurate enough to not even be able to alert about circles, don't even think about some other concrete shape).

Create smallest circular geofence which contains your polygon and if triggered just check if you are in the polygon inside with Google Maps Android API utility library.

In other words check if you are in white area not in grey:




回答2:


The Android Geofencing API only provides support for Circular Geofences. If you want to monitor Polygon shaped geofences then you have to implement it your self.

One solution would be something like this:

Get the current location update using Location API.

Now you have polygon shaped geofence. You can use ray-casting Algorithm to check if a point is inside the Closed Polygon or not?



来源:https://stackoverflow.com/questions/31847977/android-build-polygonal-shape-geofence

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!