I am making an app that needs to open Google Maps by passing waypoints. But at some point the route may change, how can I send the new route and monitor it to perform functions based on the current position?
getDirections(List<dynamic> escolaComDistancia) async {
print(escolaComDistancia);
List<PolylineWayPoint> polylineWayPoints = [];
// Utiliza a posição atual como origem
LatLng origin = LatLng(latitude.value, longitude.value);
// Define a localização da última criança como destino
Crianca ultimaCrianca = escolaComDistancia.last;
LatLng destination = LatLng(ultimaCrianca.escola.latitude, ultimaCrianca.escola.longitude);
for (int i = 0; i < escolaComDistancia.length - 1; i++) {
Crianca crianca = escolaComDistancia[i];
polylineWayPoints.add(
PolylineWayPoint(location: "${crianca.escola.latitude},${crianca.escola.longitude}"),
);
} // Adiciona os waypoints como string
String waypoints = polylineWayPoints.map((wp) => wp.location).join('|');
String googleMapsUrl = "https://www.google.com/maps/dir/?api=1"
"&origin=${origin.latitude},${origin.longitude}"
"&destination=${destination.latitude},${destination.longitude}";
if (waypoints.isNotEmpty) {
googleMapsUrl += "&waypoints=$waypoints";
}
if (await canLaunchUrl(Uri.parse(googleMapsUrl))) {
await launchUrl(Uri.parse(googleMapsUrl));
print('abriu');
} else {
throw 'Não foi possível abrir o Google Maps.';
}
it generates the new link and reaches the urllauncher however if maps is open it does not update the route, I wanted to update the link in the Google Maps app.