Flutter Google 将折线从当前位置映射到另一个位置

问题描述

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

  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

解决方法

根据您使用的方法,您似乎正在使用 flutter_polyline_points 包。

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

例如:

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