经过研究,amap_flutter_map的源代码并不多,并不直接支持在地图上画圆,经过研究,最后通过
Polygon实现了画圆的功能,但效果只能说一般般吧。下面是实现代码:
void _add() {
final Polygon polygon = Polygon(
strokeColor: Colors.blue.withAlpha(8),
fillColor: Colors.blue.withAlpha(2),
strokeWidth: 1,
points: createCirclePoints(),
);
setState(() {
selectedPolygonId = polygon.id;
_polygons[polygon.id] = polygon;
});
}
List<LatLng> createCirclePoints(){
final List<LatLng> points = <LatLng>[];
LatLng center = LatLng(39.835334, 116.3710069);
double radius = 500;
double centLatitude = center.latitude;
double centLongitude = center.longitude;
double perimeter = 2 * pi * 6371000;
//纬度latitude的地球周长:centLatitude
double perimeter_latitude = perimeter * cos(pi * centLatitude / 180);
//一米对应的经度(东西方向)1M实际度
double longitude_per_mi = 360 / perimeter_latitude;
double latitude_per_mi = 360 / perimeter;
for(int i= 0;i<360;i++){
//横向坐标的长度(米)
double pointLatLong = sin(i) * radius;
//横向坐标的长度(米)
double poinLngtLong = cos(i) * radius;
print("======= x:$pointLatLong y:$poinLngtLong");
//
double latOffset = pointLatLong*latitude_per_mi;
double lngOffset = poinLngtLong*longitude_per_mi;
LatLng point = LatLng(centLatitude + latOffset, centLongitude + lngOffset);
points.add(point);
}
return points;
}