Flutter 在 Google 地图/Apple 地图中打开导航

Far*_*han 1 navigation google-maps android-intent flutter flutter-layout

我有一个导航按钮,单击该按钮后应该打开 Google 地图或 Apple 地图应用程序(以安装的为准),并显示从当前位置到目的地位置的导航方向

我使用url_launcher包尝试了以下方法

  1. await launchUrlString("https://www.google.com/maps/dir/?api=1&origin=${position.latitude},${position.longitude}&destination=${vendorPosition.latitude},${vendorPosition.longitude}");

  2. await launchUrl(Uri.parse("google.navigation:q=${position.latitude},${position.longitude}&mode=d"));

这两种方法都没有按预期工作,特别是因为这仅使用谷歌地图 URI

在此输入图像描述

Kau*_*dru 9

还有另一个包只是为了启动地图

https://pub.dev/packages/map_launcher

final availableMaps = await MapLauncher.installedMaps;
print(availableMaps); // [AvailableMap { mapName: Google Maps, mapType: google }, ...]

await availableMaps.first.showMarker(
  coords: Coords(37.759392, -122.5107336),
  title: "Ocean Beach",
);
Run Code Online (Sandbox Code Playgroud)

它也支持谷歌地图和苹果地图。Url Launcher 的默认行为是打开默认浏览器。