[英]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 时,我想在用户移动设备中打开路由应用程序,如谷歌地图或 Waze。
ElevatedButton(
onPressed: () {
},
),
how can I do that?我怎样才能做到这一点?
use this package and do it like this:使用这个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.';
}
}
Its better to use this package like this:最好像这样使用这个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.