Home > OS >  Flutter Open Navigation in Google Maps/Apple Maps
Flutter Open Navigation in Google Maps/Apple Maps

Time:07-30

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

CodePudding user response:

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.

  • Related