1

I'm building a flutter app where I want to open the Google Maps app with directions and enforce the waypoints.

I've seen multiple examples or implementations for the same in other Stackoverflow links.

My Code:

  Future<void> launchMapsDirection(double lat, double lng) async {
    print("called");
    late final String url;
    if (Platform.isAndroid) {
      url = 'google.navigation:q=$lat,$lng';
      // url = 'https://www.google.com/maps/dir/?api=1&destination=$lat,$lng&travelmode=driving&dir_action=navigate';
      // url = 'geo:$lat,$lng';
      // url = 'https://www.google.com/maps/search/?api=1&query=$lat,$lng';
      // url = 'comgooglemaps://?daddr=$lat,$lng';
      // url = 'comgooglemaps://?q=$lat,$lng';
      // url = 'https://www.google.com/maps?daddr=$lat,$lng&dir_action=navigate';
    } else {
      url = 'comgooglemaps://?daddr=$lat,$lng';
    }
    if (await canLaunchUrl(Uri.parse(url))) {
      await launchUrl(Uri.parse(url));
    } else {
      print('cannot launch url');
    }
  }

There are multiple Urls I've formed and tested.

Only url google.navigation:q=$lat,$lng seemed to work with many android devices that opens the Google map app but this doesn't support the parameter for waypoint. document here

The url https://www.google.com/maps/dir/?api=1&destination... supports the waypoints but opens in web-view google map (not the app). I tried to open this url with Intent packages, yet opens in web-view.

Is there a way to open google maps for navigation with the waypoints? Currently looking to make it work on android only.

VipiN Negi
  • 2,994
  • 3
  • 24
  • 47

1 Answers1

0

Yes, you could use url launcher with google.navigation:q=$lat,$lng&mode=d

Ali Hajeh
  • 43
  • 1
  • 5