Home > Net >  when on press on ElevatedButton I want open Routing applications. Flutter
when on press on ElevatedButton I want open Routing applications. Flutter

Time:08-14

I get current location and my destination in app, when on press on ElevatedButton I want open Routing applications like google maps or Waze in user mobile.

  ElevatedButton(
                    onPressed: () {

                },
                ),

how can I do that?

CodePudding user response:

use this package and do it like this:

Future<void> openMap(double latitude, double longitude) async {
    String googleUrl = 'https://www.google.com/maps/search/?api=1&query=$latitude,$longitude';
    if (await canLaunch(googleUrl)) {
      await launch(googleUrl);
    } else {
      throw 'Could not open the map.';
    }
  }

CodePudding user response:

Its better to use this package like this:

Future<void> openMap(double latitude, double longitude) async {
  String googleUrl = 'https://www.google.com/maps/search/?api=1&query=$latitude,$longitude';
  var _params;
  Uri googleUri = Uri.parse(googleUrl).replace(queryParameters: _params);
  if (await canLaunchUrl(googleUri)) {
    await launchUrl(googleUri);
  } else {
    throw 'Could not open the map.';
  }
}
  • Related