Calculate distance point to line

Viewed 158

I'm using Mapbox for Android Java and need to calculate the distance between a drawn line defined by start and endpoint to the users current location.
Any idea on how to implement that with mapbox?

1 Answers

You have some Turf.js (a geospatial analysis library) methods ported to Android: https://docs.mapbox.com/android/java/guides/turf/

  1. Use TurfMisc.nearestPointOnLine() with the line and the user location as an input
  2. Then use TurfMeasurement.distance() between the two points
Related