Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Flutter Open Navigation in Google Maps/Apple Maps

I have a navigation button which when clicked on should be opening either the Google maps or the Apple maps app, whichever is installed, and show navigation directions from current location to destination location

I have tried the following approaches using the url_launcher package

  1. await launchUrlString("https://www.google.com/maps/dir/?api=1&origin=${position.latitude},${position.longitude}&destination=${vendorPosition.latitude},${vendorPosition.longitude}");

  2. await launchUrl(Uri.parse("google.navigation:q=${position.latitude},${position.longitude}&mode=d"));

Neither of the approaches are working as expected, especially since this is only using google maps URI

enter image description here

like image 572
Fardeen Khan Avatar asked May 13 '26 17:05

Fardeen Khan


1 Answers

There is another package just to launch maps

https://pub.dev/packages/map_launcher

final availableMaps = await MapLauncher.installedMaps;
print(availableMaps); // [AvailableMap { mapName: Google Maps, mapType: google }, ...]

await availableMaps.first.showMarker(
  coords: Coords(37.759392, -122.5107336),
  title: "Ocean Beach",
);

It supports google maps and apple map too.. Url Launcher's default behaviour is to open default browser.

like image 59
Kaushik Chandru Avatar answered May 16 '26 14:05

Kaushik Chandru