【问题标题】:Flutter : How to launch the Google Map app with "directions" to a predefined location?Flutter:如何使用“方向”启动谷歌地图应用程序到预定义的位置?
【发布时间】:2021-01-03 08:48:26
【问题描述】:

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

 _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,当我点击按钮时,我打开了谷歌地图,我可以清楚地看到“路线”按钮,我可以点击并开始导航。下面的例子

在 iOS 中,我打开了谷歌地图,位置指向标记,但我没有得到“方向”按钮或类似的东西,所以我可以开始导航。我该如何解决这个问题?

【问题讨论】:

  • 根据Maps URLs documentation,您可以使用以下 URL:https://www.google.com/maps/dir/?api=1&amp;parameters 启动请求路线并使用结果启动 Google 地图。你试过吗?
  • @PeakGen 你有什么成果吗?

标签: android ios google-maps flutter google-maps-markers


【解决方案1】:

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

comgooglemaps://?saddr={LAT},{LONG}&amp;daddr{LAT},{LONG}&amp;directionsmode=driving

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2010-10-07
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多