高德Flutter官方组件amap_flutter_map在地图上画圆

经过研究,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;


  }

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值