繁体   English   中英

按下 ElevatedButton 时,我想打开路由应用程序。 Flutter

[英]when on press on ElevatedButton I want open Routing applications. Flutter

我在应用程序中获取当前位置和目的地,当按下 ElevatedButton 时,我想在用户移动设备中打开路由应用程序,如谷歌地图或 Waze。

  ElevatedButton(
                    onPressed: () {

                },
                ),

我怎样才能做到这一点?

使用这个package并这样做:

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

最好像这样使用这个package

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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