path=[{lat:x,lng:y}]
computeSignedArea(path)
function computeSignedArea(path) {
//传入path:{
let radius = 6371009
let len = path.length;
if (len < 3) return 0;
let total = 0;
let prev = path[len - 1];
let prevTanLat = Math.tan(((Math.PI / 2 - prev.lat / 180 * Math.PI) / 2));
let prevLng = (prev.lng) / 180 * Math.PI;
for (let i in path) {
let tanLat = Math.tan((Math.PI / 2 -
(path[i].lat) / 180 * Math.PI) / 2);
let lng = (path[i].lng) / 180 * Math.PI;
total += polarTriangleArea(tanLat, lng, prevTanLat, prevLng);
prevTanLat = tanLat;
prevLng = lng;
}
return Math.abs(total * (radius * radius));
}
function polarTriangleArea(tan1, lng1, tan2, lng2) {
let deltaLng = lng1 - lng2;
let t = tan1 * tan2;
return 2 * Math.atan2(t * Math.sin(deltaLng), 1 + t * Math.cos(deltaLng));
}