首页 > 解决方案 > Flutter Google 将折线从当前位置映射到另一个位置

问题描述

我正在尝试将折线从当前位置绘制到颤动的另一个位置,我在网上看到的所有示例都没有这部分代码的问题。

  void setPolylines() async {
    List<PointLatLng> result = await polylinePoints.getRouteBetweenCoordinates(
        googleAPIKey,
        currentLocation.latitude,
        currentLocation.longitude,
        destinationLocation.latitude,
        destinationLocation.longitude);

上面的代码给了我下面的错误

A value of type 'PolylineResult' can't be assigned to a variable of type 'List<PointLatLng>'.

Try changing the type of the variable, or casting the right-hand type to 'List<PointLatLng>'.
Open documentation

Too many positional arguments: 3 expected, but 5 found.  Try removing the extra positional arguments, or specifying the name for named arguments. Open documentation

标签: fluttergoogle-mapspolyline

解决方案


看起来您正在使用基于您使用的方法的flutter_polyline_points包。

查看文档,您似乎需要将getRouteBetweenCoordinates方法的结果传递给PolylineResult而不是List<PointLatLng>

例如:

PolylineResult result = await polylinePoints.getRouteBetweenCoordinates(googleAPiKey,
        _originLatitude, _originLongitude, _destLatitude, _destLongitude);

推荐阅读