Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

how to Draw a line along with position changes using mapbox android #5321

Closed
Mallikarjuna1476 opened this issue Jan 4, 2022 · 4 comments
Closed

Comments

@Mallikarjuna1476
Copy link

Android API:
Mapbox Navigation SDK version:

Steps to trigger behavior

  1. Integrate Mapbox SDK
  2. If User moves from on the Road, draw the line along the user
  3. If user moves Lat\Lon coordinates will change, need to draw line even if lat\lon chnages dynamically.

Expected behavior

If user moves Lat\Lon coordinates will change, need to draw line even if lat\lon chnages dynamically.

Actual behavior

Currently by using origin and destination im able to draw line.

@cafesilencio
Copy link
Contributor

I"m not sure I understand your use case but i'll try to clarify how the Navigation SDK works. When a user moves off of the road and that is detected, a new route is fetched. Depending on connectivity and other factors there will be some delay from the time the user moves off of the route until a new route is fetched. When a reroute occurs the route line isn't automatically redrawn.

One way to redraw the route line on the map when a reroute event occurs is with a RoutesObserver. When the navigation core performs a reroute the new route will be expressed by this observer. In your implementation you should pass this route to the MapboxRouteLineApi class by calling MapboxRouteLineApi::setRoutes and rendering the result by calling MapboxRouteLineView::renderRouteDrawData. Here is a link to an example.

If I misunderstood your issue. Please clarify.

@Mallikarjuna1476
Copy link
Author

Mallikarjuna1476 commented Jan 5, 2022 via email

@cafesilencio
Copy link
Contributor

Ok, let me point out some things that might be useful to you. It might not be obvious but a line is a collection of Point objects. You can see that here (LineString.fromPolyline(geometry, 6).coordinates()). Any collection of Point objects can be used to draw a line (LineString.fromLngLats() will return a LineString that can be used to create a FeatureCollection). Using the collection of Point objects you initially get from fetching a route you can create other lines by adding/removing points from the original collection of points from the route.

I want to draw a line with a moving icon along the user.

To get an icon that moves with the user see the documentation here.

You can listen for changes in the user's location and draw updated route lines by creating new line geometry based on the original collection of Point objects and adding/removing points that have a different destination.

A library that would probably be useful to you is the Mapbox Java library.
The Map Matching API can help you with getting line geometry that is snapped to the road (if that fits your use case).

Also look at the Turf API, specifically TurfMeasurement and TurfMisc. There are methods for measuring distances between points which can tell you how far the user the user had moved off of the original route and the bearing etc. There are also methods for slicing a collection of points for creating route lines.

@cafesilencio
Copy link
Contributor

Closing this for lack of activity.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants