【问题标题】:Flutter Google maps polylines from current location to another locationFlutter Google 将折线从当前位置映射到另一个位置
【发布时间】:2021-09-17 19:50:23
【问题描述】:

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

  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 包来绘制折线?什么版本?

标签: flutter google-maps polyline


【解决方案1】:

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

查看文档,看来您需要将getRouteBetweenCoordinates 方法的结果传递给PolylineResult 而不是List&lt;PointLatLng&gt;

例如:

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

【讨论】:

  • 这将是一个昂贵的电话,我猜。有没有什么简单的方法可以在用户向目的地前进时移除该点并显示用户当前位置和目的地的折线。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2021-10-09
  • 1970-01-01
相关资源
最近更新 更多