Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android: Build Polygonal Shape Geofence

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,

like image 577
michael Avatar asked Aug 06 '15 06:08

michael


Video Answer


1 Answers

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:

enter image description here

like image 54
Marian Paździoch Avatar answered Oct 10 '22 11:10

Marian Paździoch