Current, i'm implement tracking + navigation to specific point by updating polyline on change of current location. this process is very costly because it calling direction Api on every new location. I want to update polyline by calling one time google direction api and then update it statically or as google uses it in google maps app.
Try Start Navigation Function
it looks like this
startNavigation() async {
var pickUp = await getBytesFromAsset(AppIcons.navMarker, 80, 80);
var dest = await getBytesFromAsset(AppImages.destMarker, 40, 40);
location.changeSettings(
accuracy: LocationAccuracy.navigation,
);
location.enableBackgroundMode(enable: true);
timer = Timer.periodic(const Duration(seconds: 1), (timerValue) {
timer = timerValue;
location.getLocation().then((l) async {
pickLatitude.value = l.latitude!;
pickLongitude.value = l.longitude!;
if (isNavigationStarted.value == true) {
await getPolyline().then((value) {
markers.clear();
cameraZoom.value = 18;
Set<Circle> circles2 = {
Circle(
circleId: const CircleId("dsd"),
center: LatLng(l.latitude!, l.longitude!),
fillColor: Colors.blue.shade100.withOpacity(0.5),
strokeColor: Colors.blue.shade100.withOpacity(0.1),
radius: 20,
)
};
circles.value = circles2;
addMarker(
position: LatLng(l.latitude!, l.longitude!),
id: "pickup",
rotation: l.heading!,
descriptor: BitmapDescriptor.fromBytes(pickUp),
anchor: const Offset(0.5, 0.5),
);
addMarker(
position: LatLng(destination.center.latitude.toDouble(),
destination.center.longitude.toDouble()),
id: "dest",
rotation: l.heading!,
descriptor: BitmapDescriptor.fromBytes(dest),
anchor: const Offset(0.5, 0.5),
);
updateCameraPositionForNavigation();
var difference = distanceBetweenLatLng(
LatLng(l.latitude!, l.longitude!),
LatLng(destination.center.latitude.toDouble(),
destination.center.longitude.toDouble()));
});
} else {
markers.clear();
cameraZoom.value = 18;
Set<Circle> circles2 = {
Circle(
circleId: const CircleId("dsd"),
center: LatLng(l.latitude!, l.longitude!),
fillColor: Colors.blue.shade100.withOpacity(0.5),
strokeColor: Colors.blue.shade100.withOpacity(0.1),
radius: 20,
)
};
circles.value = circles2;
addMarker(
position: LatLng(l.latitude!, l.longitude!),
id: "pickup",
rotation: l.heading!,
descriptor: BitmapDescriptor.fromBytes(pickUp),
anchor: const Offset(0.5, 0.5),
);
updateCameraPostionBasedOnVisibility();
}
});
});
}
Expected
Google like Navigation + tracking which lower the cost of direction Api