高德地图 JS API示例->几何计算->距离/面积计算-> 区域面积

高德地图 JS API示例->几何计算->距离/面积计算-> 区域面积

使用 AMap.GeometryUtil.ringArea 计算区域,返回数据以平方米为单位。

<!doctype html>
<html>
<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="initial-scale=1.0, user-scalable=no, width=device-width">
    <title>面积计算</title>
    <link rel="stylesheet" href="https://a.amap.com/jsapi_demos/static/demo-center/css/demo-center.css" type="text/css">
    <style>
      html,body,#container{
        height: 100%
      }
    </style>
</head>
<body>
<div id="container"></div>
<script type="text/javascript" src="https://webapi.amap.com/maps?v=1.4.15&key=您申请的key值"></script>
<script type="text/javascript">
    //初始化地图对象,加载地图
    var map = new AMap.Map("container", {
        resizeEnable: true,
        zoom: 10
    });
    var path = [
        [116.169465,39.932670],
        [116.160260,39.924492], 
        [116.150625,39.710019],
        [116.183198,39.709920], 
        [116.226950,39.777616], 
        [116.442621,39.799892],
        [116.463478,39.790066], 
        [116.588276,39.809551],
        [116.536091,39.808859],
        [116.573856,39.839643], 
        [116.706380,39.916740],
        [116.600293,39.937770],
        [116.514805,39.982375],
        [116.499935,40.013710],
        [116.546520,40.030443], 
        [116.687668,40.129961], 
        [116.539697,40.080659],
        [116.503390,40.058474],
        [116.468800,40.052578]
    ];
    var polygon = new AMap.Polygon({
        map: map,
        fillOpacity:0.4,
        path: path
    });
    // 计算区域面积
    var area = Math.round(AMap.GeometryUtil.ringArea(path));
    var text = new AMap.Text({
        position: new AMap.LngLat(116.468800,40.052578),
        text: '区域面积' + area + '平方米',
        offset: new AMap.Pixel(-20, -20)
    })
    map.add(text);
    map.setFitView();
</script>
</body>
</html>
0 0 投票数
文章评分
订阅评论
提醒
0 评论
最旧
最新 最多投票
内联反馈
查看所有评论
0
希望看到您的想法,请您发表评论x