/**
* 地图点位-站点搜索周边
*/
async getStationAroundData(content, { ctx, userid }) {
let { jd = "0", wd = "0",distance } = content
// distance 距离是m为单位
let jd_new = jd,
wd_new = wd
const allStation=await this.airjgMapDetail({code:440000})
let list = []
for(let item of allStation){
item.distance = this.algorithm([wd_new, jd_new], [item.lat, item.lng])
if (item.distance > distance) continue
list.push(item)
}
list = list.sort((a, b) => a.distance - b.distance)
list.forEach((v, index) => {
v.index = ++index
v.zj = v._id
})
return list
}
// 计算两点之间直线距离
algorithm(point1, point2) {
let [x1, y1] = point1
let [x2, y2] = point2
let Lat1 = this.rad(x1)
let Lat2 = this.rad(x2)
let a = Lat1 - Lat2
let b = this.rad(y1) - this.rad(y2)
let s =
2 *
Math.asin(
Math.sqrt(Math.pow(Math.sin(a / 2), 2) + Math.cos(Lat1) * Math.cos(Lat2) * Math.pow(Math.sin(b / 2), 2))
)
// 计算两点距离的公式
s = s * 6378137.0
s = Math.round(s * 10000) / 10000
return s
}
//将用角度表示的角特换为近似想等的用弧度表示的角 java Math.toRadians
rad(d) {
return (d * Math.PI) / 180.0
}