Google Map Navigation in Flutter

别等时光非礼了梦想. 提交于 2019-12-28 12:42:47

问题


I'm new to flutter.

I found Flutter doesn't support inline map, only a static map view.

I wanted to build an app which I need to show the driving directions on the map.

Is it possible to create the same in flutter?


回答1:


you can use android_intent library in flutter for starting googlemaps and get diection in android.

library : https://pub.dartlang.org/packages/android_intent

and in ios you can use both google api like comgooglemaps or google map url {i choose this one} and 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';
       }
    }

i hope it helps.




回答2:


At the time of writing this answer, the work on inline maps is still in progress. But since the guys at flutter have given others the ability to develop plugins, there are some alternatives.

You might want to check out :

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

If you just want to get the location of your user:

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

If you want to keep a watch out for new updates, I found some interesting discussions going on here:

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




回答3:


https://github.com/eopeter/flutter_mapbox_navigation here is your solution.it works for me



来源:https://stackoverflow.com/questions/51337998/google-map-navigation-in-flutter

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!