2

is it possible to follow a path on google map android (Programmatically) if my android device getting away from the path it notify or show alert that your not following your path

Help will be appriciated, Thank's :)

Muhammad Waqas
  • 420
  • 4
  • 19
  • have look [this](https://stackoverflow.com/questions/30249920/how-to-draw-path-as-i-move-starting-from-my-current-location-using-google-maps) – Hemant Parmar May 09 '18 at 04:40
  • Thanks dear but my question is different , if I have a path drawn on google map between two points and i wanna move from starting point to end point but android app force me to follow the exact path if a user not following the path it alert him that you are not on your path – Muhammad Waqas May 09 '18 at 04:43

1 Answers1

1

Yes, it's possible by several ways. For example you can use PolyUtil.isLocationOnPath(LatLng point, java.util.List<LatLng> polyline, boolean geodesic, double tolerance) from Google Maps Android API Utility Library. In this case you need to check (with isLocationOnPath()) if user location laying on segment of the polyline of your path. Something like that:

if (!PolyUtil.isLocationOnPath(userLocationPoint, pathPolyline.getPoints(), true, 50)) {
        // user away of pathPolyline more than 50 meters
        // show your alert here
        ...
    }
}

where 50 - is tolerance (in meters). NB! It's not a complete solution - just approach.

Also you can use geofence monitoring for several waypoints (with a limit of 100 per device user).

Andrii Omelchenko
  • 13,183
  • 12
  • 43
  • 79
  • Thank you it works for me and can you please elaborate what does actually do tolerance? – Muhammad Waqas May 10 '18 at 06:07
  • tolerance 50 means it will allow all the geo point which are in the range of 50 meter right ? – Muhammad Waqas May 10 '18 at 06:09
  • 1
    @MuhammadWaqas You're welcome. From [documentation](http://googlemaps.github.io/android-maps-utils/javadoc/com/google/maps/android/PolyUtil.html#isLocationOnPath-LatLng-java.util.List-boolean-double-): "given point lies on or near a polyline, within a specified tolerance in meters. The polyline is composed of great circle segments if geodesic is true" - so it means 50 meters range for each "side" (100 m interval). Also, you can study source code of `PulyUtils.isLocationOnEdgeOrPath()`. – Andrii Omelchenko May 10 '18 at 06:58