【发布时间】:2015-11-18 16:19:53
【问题描述】:
如何使用javascript根据一组经纬度值计算面积?
我有一组从我自己的数据库中提取的纬度和经度值。它们看起来像这样:
// Define the LatLng coordinates for the polygon's path.
var fizuliCoords = [
{lng:47.1648244,lat:39.6834661},
{lng:47.1653823,lat:39.6906634},
........there are 400-1200 lines...I only list 2
];
var bakuCoords = [
{lng:47.1648244,lat:39.6834661},
{lng:47.1653823,lat:39.6906634},
........there are 400-1200 lines...I only list 2
];
有69个不同的行政区域
我的项目是:
- 列出多边形
- 根据一组纬度/经度值自动计算面积 我是一个完全的新手-所以请耐心等待我:) 我可以从一个名为 Expert GPS 的程序中提取以平方公里为单位的区域,而已知 shpaes 没有问题,但我需要一个自动化脚本。 谢谢 ...... 抱歉,第一次来:)
好的,
<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="initial-scale=1.0, user-scalable=no">
<meta charset="utf-8">
<title>ttttt</title>
<style>
html, body {
height: 100%;
margin: 0;
padding: 0;
}
/* #map is the div that places map on the html page*/
#map {
height: 100%;
}
/* end of #map */
</style>
</head>
<body>
<div id="map"></div>
<script>
// This example creates a simple polygon representing the shusha Region.
//the initMapfunction places the map on the page
function initMap() {
var map = new google.maps.Map(document.getElementById('map'), {
zoom: 8,
center: {lat: 40.352310, lng: 47.999462},
mapTypeId: google.maps.MapTypeId.TERRAIN
});
//end oof initMap function
//------------------------------------------------------------------
// Define the LatLng coordinates for the Shusha polygon's path.
var shushaCoords = [
{lng:46.5852069,lat:39.7918524},
{lng:46.5810012,lat:39.789016},
{lng:46.5800569,lat:39.7812995},
{lng:46.5741348,lat:39.7757586},
{lng:46.5720748,lat:39.7722619},
{lng:46.571817,lat:39.763026}
];
// Define the LatLng coordinates for the Khojavend polygon's path.
var khojavendCoords = [
{lng:46.6707802,lat:39.5735368},
{lng:46.6646003,lat:39.5704934},
{lng:46.6628837,lat:39.5675823}
];
// Define the LatLng coordinates for the Zangilan polygon's path.
var xocaliCoords = [
{lng:46.6195822,lat:39.233882},
{lng:46.6161489,lat:39.232918},
{lng:46.6094971,lat:39.2322199},
{lng:46.6076088,lat:39.2318542},
{lng:46.6009998,lat:39.229494}
];
**and so on for 69 more areas then come the polygons**
**// Construct the xocali polygon.**
var xocali = new google.maps.Polygon({
map: map,
paths: xocaliCoords,
strokeColor: '#000000',
strokeOpacity: 0.5,
strokeWeight: 2,
fillColor: '#00CCFF',
fillOpacity: 0.15
});
**//and then 68 more**
// Add a listener for the julfa mouseover/mouseout event.
google.maps.event.addListener(julfa ,'mouseover',function(){
this.setOptions({fillColor: "#00FF00"});
});
**//here I would like to add a popup where the AREA will be calculated**
google.maps.event.addListener(julfa ,'mouseout',function(){
this.setOptions({fillColor: "#00CCFF"});
});
//and then 68 more sets of listeners
}
</script>
<!--end of mapping script-->
<!--the script below is the googleAPI browser script, if i need to display on the server - must change to Server API code.-->
<script async defer src="https://maps.googleapis.com/maps/api/js? key=xxxxxxxxxxxxxxxxx&signed_in=true&callback=initMap"></script>
</body>
</html>
所以我在这里有 3 个问题: 1. 能够构造一个公式,根据每个多边形的 lat lng 值计算面积 2. 在弹出窗口中完成此操作 3.可以使用外部.js文件
【问题讨论】:
标签: javascript google-maps google-maps-api-3 gps