You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
72 lines
1.7 KiB
72 lines
1.7 KiB
function test() { |
|
return 1 + 1 |
|
} |
|
/** |
|
* 获取两个经纬度之间的距离 |
|
* @param lat1 第一点的纬度 |
|
* @param lng1 第一点的经度 |
|
* @param lat2 第二点的纬度 |
|
* @param lng2 第二点的经度 |
|
* @returns {Number} |
|
*/ |
|
function getRad(d) { |
|
var PI = Math.PI; |
|
return d * PI / 180.0; |
|
} |
|
|
|
function getDistance(lat1, lng1, lat2, lng2) { |
|
var f = getRad((lat1 + lat2) / 2); |
|
var g = getRad((lat1 - lat2) / 2); |
|
var l = getRad((lng1 - lng2) / 2); |
|
var sg = Math.sin(g); |
|
var sl = Math.sin(l); |
|
var sf = Math.sin(f); |
|
var s, c, w, r, d, h1, h2; |
|
var a = 6378137.0; //The Radius of eath in meter. |
|
var fl = 1 / 298.257; |
|
sg = sg * sg; |
|
sl = sl * sl; |
|
sf = sf * sf; |
|
s = sg * (1 - sl) + (1 - sf) * sl; |
|
c = (1 - sg) * (1 - sl) + sf * sl; |
|
w = Math.atan(Math.sqrt(s / c)); |
|
r = Math.sqrt(s * c) / w; |
|
d = 2 * w * a; |
|
h1 = (3 * r - 1) / 2 / c; |
|
h2 = (3 * r + 1) / 2 / s; |
|
s = d * (1 + fl * (h1 * sf * (1 - sg) - h2 * (1 - sf) * sg)); |
|
// s = s/1000; |
|
s = s.toFixed(2); //指定小数点后的位数。 |
|
return s; |
|
} |
|
|
|
function ab2str(buf) { |
|
return String.fromCharCode.apply(null, new Uint16Array(buf)); |
|
} |
|
|
|
function str2ab(str) { |
|
var buf = new ArrayBuffer(str.length * 2); // 2 bytes for each char |
|
var bufView = new Uint16Array(buf); |
|
for (var i = 0, strLen = str.length; i < strLen; i++) { |
|
bufView[i] = str.charCodeAt(i); |
|
} |
|
return buf; |
|
} |
|
function distance(res){ |
|
let ALWAYS = []; |
|
res.markes.forEach((item,index)=>{ |
|
let distance = utils.getDistance(res.coordinate.latitude,res.coordinate.longitude,item.latitude, item.longitude); |
|
if(distance<1000){ |
|
ALWAYS.push(index) |
|
} |
|
}); |
|
return ALWAYS |
|
} |
|
|
|
module.exports = { |
|
distance:distance, |
|
test: test, |
|
ab2str: ab2str, |
|
str2ab: str2ab, |
|
getDistance: getDistance |
|
}
|
|
|