简体   繁体   中英

when on press on ElevatedButton I want open Routing applications. Flutter

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?

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.';
    }
  }

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.';
  }
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM