当前位置:网站首页>js序获取两地距离
js序获取两地距离
2022-06-09 15:11:00 【weixin_44387746】
// 判断两经纬度之间的距离
var PI = Math.PI;
var EARTH_RADIUS = 6378137.0;//单位M
function getRad(d) {
return d * PI / 180.0;
}
function getFlatternDistance(lat1, lng1, lat2, lng2) {
lat1 = parseFloat(lat1);
lng1 = parseFloat(lng1);
lat2 = parseFloat(lat2);
lng2 = parseFloat(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 = EARTH_RADIUS;
var fl = 1 / 298.257;
if (sg == sl && sg == 0 && sl == 0) {
return 0;
}
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;
// console.log(d * (1 + fl * (h1 * sf * (1 - sg) - h2 * (1 - sf) * sg)))
return d * (1 + fl * (h1 * sf * (1 - sg) - h2 * (1 - sf) * sg));
}
// 自动获取定位
// let option = {
// collectionName: "weisa", //数据库表名
// queryWay: "find", //操作类型
// // screen: { "省": '广东省' } //查询条件
// }
// cloud.function.invoke('myCloud', option, 'main').then(res => {
// // console.log(res)
// let list = []
// for (var i = 0; i < res.length; i++) {
// // console.log(that.data.latitude,res[i].纬度)
// list.push(getFlatternDistance(that.data.latitude, that.data.longitude, res[i].经度, res[i].纬度))
// }
// // console.log(this.data.province)
// const minNum = Math.min(...list)
// const [minIndex] = [list.indexOf(minNum)]
// // console.log(minNum, minIndex)
// // console.log(res[minIndex])
// this.setData({
// address: res[minIndex].店铺名称,
// latitude: res[minIndex].经度,
// longitude: res[minIndex].纬度,
// alladdress: res[minIndex].详细地址,
// })
// });
边栏推荐
- Geoffrey Hinton最新访谈:不出五年,我们就会破解大脑的运作机制,但不是通过反向传播
- Docker-Compose实现Mysql主从
- List used by icomponent of unity dots
- How to write a test report approved by a large manufacturer? With these 30 sets of templates, I take off completely
- @Enablefeignclients annotation source code analysis
- Due to the suspension of Russian business: IBM Q1 lost 2billion, Cisco 1.3 billion, Adobe 500million, HP 6.7 billion, uipath 100million
- Some tool functions commonly used in JS projects
- A Baidu programmer was sentenced to: dissatisfied with others taking over the project, showing his own role, deleting and modifying the database for many times, and committing the crime of destroying
- cx_ oracle ORA-01036
- 497. 非重叠矩形中的随机点
猜你喜欢

QT MSVC compiler Chinese problem solving, Chinese garbled and unable to compile normally

Hongmeng transplants the compiling system of i.mx6ull (VII) liteos-a

【实战】Redis Cluster(下)-系统版本支持问题
![[paper] cascade r-cnn: delving into high quality object detection](/img/7d/f5ebd89cd8963fe45d4894077ca25b.png)
[paper] cascade r-cnn: delving into high quality object detection

Performance monster on arm64: installation and performance test of API gateway Apache APIs IX on AWS graviton3

品牌焕新、产品上新、营销创新,东风标致的向上之路.

【论文】Cascade R-CNN: Delving into High Quality Object Detection
Windows版mysql 8.0.28 安装配置方法图文教程

分布式限流之基于Sentinel实现的限流漫谈(一)-概述

博文推荐|BookKeeper - Apache Pulsar 高可用 / 强一致 / 低延迟的存储实现
随机推荐
jupyter lab学习笔记
技术干货 | Linkis实践:新引擎实现流程解析
View lazy loading in applet
How insecure is NFT from copyright to assets?
浅谈Redis常见延迟问题定位与分析
【五、反向代理及其相关配置】
博文推荐|BookKeeper - Apache Pulsar 高可用 / 强一致 / 低延迟的存储实现
Halodoc使用 Apache Hudi 构建 Lakehouse的关键经验
Taoist friends! What is the expiration policy of redis?
mongoose连接多个数据库简单例子
3 个技巧来破解你可以立即使用的 Flutter 生产力!
信息学奥赛一本通 1260 【例9.4】拦截导弹(Noip1999) | 洛谷 P1020 [NOIP1999 普及组] 导弹拦截
Triangular constant strain element (CST) derived from area coordinates
Fcpx plug-in: motion blur FX by Ma
华为哈勃将再添IPO,美芯晟蛰伏十余年后冲刺科创板
被大厂认可的测试报告怎么写?拥有这30套模板的我彻底起飞
Hongmeng porting i.mx6ull (VIII) memory mapping (based on imx6ull)
Simple example of mongoose connecting multiple databases
最成功也最差劲的CEO去世,索尼还是走在他的老路上
国货彩妆,败走618