0
String  map = widget.list[widget.index]['map'];

地图数据的示例"[LatLng(12.82879876203614, 80.12908793985844),LatLng(12.83370395257544, 80.1245865225792),LatLng(12.839642030904889, 80.12061484158039),]" 现在是字符串,但我想要 LatLng 格式(不带“”双引号),例如[LatLng(12.82879876203614, 80.12908793985844),LatLng(12.83370395257544, 80.1245865225792),LatLng(12.839642030904889, 80.12061484158039),]

     Set<Polygon> polygonSet = new Set();
  polygonSet.add(Polygon(
      polygonId: PolygonId('test'),
      points: map,
      strokeWidth: 2,
      strokeColor: Colors.blue,
      fillColor: Colors.blue.withOpacity(0.4),));

  return polygonSet;
}

输出错误:type 'String' is not a subtype of type 'LatLng'

4

1 回答 1

0

您可以使用 jsonDecode() 将字符串转换为 LatLng 列表。

import 'dart:convert';

void main() {
  String map =
      '"[LatLng(12.82879876203614, 80.12908793985844),LatLng(12.83370395257544, 80.1245865225792),LatLng(12.839642030904889, 80.12061484158039),]"';
  List<LatLng> latlngList = jsonDecode(map);
  print(latlngList);
}

输出将是:

[LatLng(12.82879876203614, 80.12908793985844),LatLng(12.83370395257544, 80.1245865225792),LatLng(12.839642030904889, 80.12061484158039),]
于 2021-09-21T03:13:26.167 回答