从列表LatLng颤振飞镖编码折线

时间:2020-05-17 12:24:09

标签: flutter dart

新手问题。我是飞镖/颤振的新手,但是正在开发一个应用程序,其中我必须将List<LatLng>坐标转换为嵌套的List<List<num>>。这样就可以使用另一个辅助函数将其编码为折线。

这是我的错误:

Error: The argument type 'List<LatLng>' can't be assigned to the parameter type 'List<List<num>>'.

这是从List<LatLng>创建我的List<PointLatLng>的地方。

final List<PointLatLng> result =
                        await polylineGetter.getRouteBetweenCoordinates(
                      apiKEY,
                      _curLoc.latitude,
                      _curLoc.longitude,
                      geolocation.coordinates.latitude,
                      geolocation.coordinates.longitude,
                    );
final List<LatLng> polylineCoordinates = [];

                    for (var point in result) {
                      polylineCoordinates
                          .add(LatLng(point.latitude, point.longitude));
                    }

如何将其转换为通用的嵌套列表,以从其他库输入此帮助器函数?以下是我需要在其中使用硬编码值进行转换的示例。

final coords = encodePolyline([[38.5, -120.2],[40.7, -120.95],[43.252, -126.453],]);

这是我需要使用的功能

encodePolyline(List<List<num>> coordinates, {int accuracyExponent = 5}) //encodes a list of coordinates into an encoded polyline stirng

尝试了几件事,但没有运气,但不确定要怎么做。预先感谢!

1 个答案:

答案 0 :(得分:1)

我们假设坐标为列表

List<List<int>> result = coordinates.map( (data) => [ data.latitude , data.longitude ] ) ;