Android: creating a polygon Geofence

According to the API documentation, only round Geofences are allowed:

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

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

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

I want to avoid the decision to create my location monitoring service extending Geofences monitoring functionality because I believe this kind of service is CPU and power consumption ...

Thank,

+3


source to share


2 answers


You have to do it yourself (but I think this is pretty pointless - the geolocation / location services are not accurate enough to not even be able to alert about circles, not even think about any other specific shape).

Create the smallest circle geofence that contains your polygon, and if called, just check if you are inside the polygon inside using the Google Maps Android API utility .



In other words, check if you are in the white area:

enter image description here

+6


source


The Android Geofencing API only supports Circular Geofences. If you want to control geophones with a polygon, then you have to implement it yourself.

One solution would be something like this:



Get the current location update using the API.

You now have a polygon shaped geo. Can you use ray casting algorithm to check if a point is inside a closed polygon or not?

0


source







All Articles