gpt4 book ai didi

android - flutter : How to launch the Google Map app with "directions" to a predefined location?

转载 作者:行者123 更新时间:2023-12-03 08:35:44 25 4
gpt4 key购买 nike

在我的 flutter 代码中,我将通过单击按钮启动具有预定义位置的 Google map 应用程序。下面是代码

 _launchMaps(double lat, double lon) async {
String googleUrl =
'comgooglemaps://?center=${lat},${lon}';
String appleUrl =
'https://www.google.com/maps/search/?api=1&query=$lat,$lon';
if (await canLaunch("comgooglemaps://")) {
print('launching com googleUrl');
await launch(googleUrl);
} else if (await canLaunch(appleUrl)) {
print('launching apple url');
await launch(appleUrl);
} else {
throw 'Could not launch url';
}
}

在 iOS 中,我确实将以下行添加到 info.plist 文件中

<key>LSApplicationQueriesSchemes</key>
<array>
<string>googlechromes</string>
<string>comgooglemaps</string>
</array>

Android 中,当我单击该按钮时,我会打开谷歌地图,并且我可以清楚地看到“方向”按钮,我可以单击该按钮并开始导航。下面的例子

enter image description here

在 iOS 中,我打开了 Google map ,位置在标记中指向,但我没有看到“方向”按钮或类似的按钮,因此我无法开始导航。我该如何解决这个问题?

最佳答案

docs 中所述,您需要在 URL 上定义起点经纬度和终点经纬度,以提示方向导航。 URL 应类似于:

comgooglemaps://?saddr={LAT},{LONG}&daddr={LAT},{LONG}&directionsmode=drive

关于android - flutter : How to launch the Google Map app with "directions" to a predefined location?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/63921431/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com