1

How to make MapBox SDK(Android) so that when the user moves around the map, a line is drawn behind him in real time (his movement itself)

1 Answers1

1

https://docs.mapbox.com/help/tutorials/android-location-listening/ shows how to track a user's location.

Every time a new Location arrives in onSuccess(), you'll:

  1. create a Point (Point point = Point.fromLngLat(LONGITUDE, LATITUDE);) with the Location object's coordinates.
  2. Add the Point to a list of Points to create a LineString.

    LineString lineString = LineString.fromLngLats(pointList);

  3. Use the LineString to update the LineLayer's geojson with the new LineString (see the second code snippet box in https://docs.mapbox.com/android/java/overview/geojson/#geojson-updates.

All of this is basically a combination of https://docs.mapbox.com/help/tutorials/android-location-listening and https://docs.mapbox.com/android/maps/examples/moving-icon-with-trailing-line (without the animation or PointEvaluator stuff from the second example, because you don't need it to move the device location puck).

langsmith
  • 2,529
  • 1
  • 11
  • 13
  • Hi! I am struggling for adding a simple line... using the new version 10.6. Would you have any hint regarding the question I just posted? https://stackoverflow.com/questions/72930297/draw-in-real-time-a-line-that-corresponds-to-the-users-route-using-mapbox-and-a – nibbana Jul 10 '22 at 18:26