Neria Nachum Neria Nachum - 1 month ago 4x
Android Question

Geofences for a route in Android

Having a route as a set of locations, I want to know when the user deviates from it using geofences. At the moment I'm creating a geofence for each location on the route, but it doesn't really cover the route in a sensible way (example below).

I want to replace this:
Wrong geofencing

With something such as this:
Right geofencing

Currently, I can only think of manually calculating locations on the route every X meters and adding more geofences, but it seems more like a band aid rather than a good solution.

Is there a way to achieve something similar to the second photo without many many small geofences, or is this the only way?



Following Robert's answer, I eventually used a similar method in Google Maps Android API utility library named PolyUtil.isLocationOnPath().