gpt4 book ai didi

ios - 如何计算iOS map 中多边形的面积

转载 作者:行者123 更新时间:2023-11-29 13:00:21 25 4
gpt4 key购买 nike

这个问题与下面的问题类似。但我问这个问题是因为那个问题没有回答要求。

Area of an irregular polygon using side lengths in ios

应用概览

1 - 用户使用他的 iPhone/iPad 在他的车辆上移动,我们应该绘制他的坐标。

2 - 在他完成骑行后,我们假设绘制一个覆盖他所有坐标的多边形

3 - 计算多边形覆盖的面积。

我引用了 map API,但找不到任何计算面积的方法。

是否有任何第 3 方库/机制可以帮助我计算 iOS map 中多边形的面积..

最佳答案

来自Google Maps v3 API documentation ,几何函数是默认情况下未加载的库的一部分:

本文档中的概念指的是仅在 google.maps.geometry 库中可用的功能。当您加载 Maps Javascript API 时,默认情况下不会加载此库,但必须通过使用库引导参数明确指定。

为了在您的页面中加载和使用几何函数,您需要通过包含 libraries=geometry 将其添加到您的初始 Google API 调用来通知 Google 您将使用几何库:

然后这将加载几何库并且您的 z 变量将包含一个对象。

带有工作代码的测试页面:

<!DOCTYPE html>
<html>
<head>
<style type="text/css">
html, body, #map_canvas {
margin: 0;
padding: 0;
height: 100%;
}
</style>
<script type="text/javascript" src="https://maps.googleapis.com/maps/api/js?libraries=geometry&sensor=false"></script>
<script type="text/javascript">
var map;
function initialize()
{
var myOptions = {
zoom: 8,
center: new google.maps.LatLng(-34.397, 150.644),
mapTypeId: google.maps.MapTypeId.ROADMAP
};
map = new google.maps.Map(document.getElementById('map_canvas'), myOptions);
}

google.maps.event.addDomListener(window, 'load', initialize);
</script>
<script>
function test()
{
var arr = new Array()
arr.push('51.5001524,-0.1262362');
arr.push('52.5001524,-1.1262362');
arr.push('53.5001524,-2.1262362');
arr.push('54.5001524,-3.1262362');
dibuV(arr);
}
function dibuV(area)
{
var a = new Array();

for(var i=0; i<area.length; i++)
{
var uno = area[i].split(",");
a[i] = new google.maps.LatLng(uno[0],uno[1]);
}

poligon = new google.maps.Polygon({
paths: a,
strokeColor: "#22B14C",
strokeOpacity: 0.8,
strokeWeight: 2,
fillColor: "#22B14C",
fillOpacity: 0.35
})

poligon.setMap(map);//until here is ok
var z = google.maps.geometry.spherical.computeArea(myPolyline.getPath().getArray());
alert(z);
}
</script>
</head>
<body onload="test();">
<div id="map_canvas"></div>
</body>
</html>

关于ios - 如何计算iOS map 中多边形的面积,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19922812/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com