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 Answers
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:
- create a
Point
(Point point = Point.fromLngLat(LONGITUDE, LATITUDE);
) with theLocation
object's coordinates. Add the
Point
to a list ofPoint
s to create aLineString
.LineString lineString = LineString.fromLngLats(pointList);
Use the
LineString
to update theLineLayer
's geojson with the newLineString
(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).

- 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