sushil chhetri
sushil chhetri

Reputation: 49

: How to Update Navigation Polyline in Maplibre Android without Repeated API Calls?

I am using Maplibre on Android and I'm new to this. I want to create a navigation polyline that updates as the user travels, using the user's current location. I have successfully obtained the DirectionsRoute from the API and created a polyline on the map, but I need to update this polyline as the user moves without hitting the API repeatedly.

Here's what I have tried so far:

Point directionIconPoint = Point.fromLngLat(location.getLongitude(), location.getLatitude());
for (Point point : decodeLinerStringPolyline(routeProgress.directionsRoute().geometry())) {
    if (isPointAhead(point, directionIconPoint)) {
        trimmedPoints.add(point);
    }
}

FeatureCollection trimmedLine = FeatureCollection.fromFeature(
        Feature.fromGeometry(LineString.fromLngLats(trimmedPoints)));
routeLineSourceTest.setGeoJson(trimmedLine); 

What I Need Help With -> How can I efficiently update the navigation polyline based on the user's current location? -> Is there a better way to filter and update the polyline without hitting the API again?

Any help or guidance would be greatly appreciated. I'm new to Maplibre and navigating polyline updates, so detailed explanations or code snippets would be very helpful.

Thank you!

Upvotes: 0

Views: 66

Answers (0)

Related Questions