Flutter中的Google Map Navigation

Jay*_*eep 5 navigation google-maps mkmapview android-mapview flutter

我是新来的。

我发现Flutter不支持嵌入式地图,仅支持静态地图视图。

我想建立一个应用程式,需要在地图上显示行车路线。

是否可以在颤动中创建相同的内容?

在此处输入图片说明

ben*_*min 12

您可以在 flutter 中使用 android_intent 库来启动 googlemaps 并在 android 中获取指令。

https :

//pub.dartlang.org/packages/android_intent,在 ios 中,您可以同时使用 google api,如 comgooglemaps 或 google map url {i choose this one} 和 maps.apple.com。

String origin="somestartLocationStringAddress or lat,long";  // lat,long like 123.34,68.56
String destination="someEndLocationStringAddress or lat,long";
if (new LocalPlatform().isAndroid) {
      final AndroidIntent intent = new AndroidIntent(
          action: 'action_view',
          data: Uri.encodeFull(
              "https://www.google.com/maps/dir/?api=1&origin=" +
                  origin + "&destination=" + destination + "&travelmode=driving&dir_action=navigate"),
          package: 'com.google.android.apps.maps');
      intent.launch();
    }
    else {
        String url = "https://www.google.com/maps/dir/?api=1&origin=" + origin + "&destination=" + destination + "&travelmode=driving&dir_action=navigate";
        if (await canLaunch(url)) {
              await launch(url);
       } else {
            throw 'Could not launch $url';
       }
    }
Run Code Online (Sandbox Code Playgroud)

我希望它有帮助。

  • OP问他想构建一个显示方向的应用程序,你的回答只是打开带有导航的谷歌地图应用程序。 (2认同)

Sun*_*tam 2

在撰写此答案时,内联地图的工作仍在进行中。但由于 flutter 的人已经给了其他人开发插件的能力,所以还有一些替代方案。

您可能想查看:

https://medium.com/@matthew.smith_66715/maps-in-flutter-a1ac49ab554b

如果您只想获取用户的位置:

https://pub.dartlang.org/packages/location

如果您想留意新的更新,我发现这里有一些有趣的讨论:

https://github.com/flutter/flutter/issues/73