网上找的中文的例子都不靠谱,还得是英文网站好用。
网址: https://www.movable-type.co.uk/scripts/latlong.html
Haversine formula
Using Chrome on a middling Core i5 PC, a distance calculation takes around 2 – 5 microseconds (hence around 200,000 – 500,000 per second). Little to no benefit is obtained by factoring out common terms; probably the JIT compiler optimises them out.
formula:
a = sin²(Δφ/2) + cos φ1 ⋅ cos φ2 ⋅ sin²(Δλ/2) |
c = 2 ⋅ atan2( √a, √(1−a) ) |
d = R ⋅ c
|
where | φ is latitude, λ is longitude, R is earth’s radius (mean radius = 6,371km); note that angles need to be in radians to pass to trig functions! |
Javascript:
var R =6371e3;// metresvarφ1= lat1.toRadians(); varφ2= lat2.toRadians();varΔφ=(lat2-lat1).toRadians(); varΔλ=(lon2-lon1).toRadians(); var a =Math.sin(Δφ/2)*Math.sin(Δφ/2)+Math.cos(φ1)*Math.cos(φ2)*Math.sin(Δλ/2)*Math.sin(Δλ/2); var c =2*Math.atan2(Math.sqrt(a),Math.sqrt(1-a));var d = R * c;
Spherical Law of Cosines
the simple spherical law of cosinesformula (cos c = cos a cos b + sin a sin b cos C) gives well-conditioned results down to distances as small as a few metres on the earth’s surface
formula:
d = acos( sin φ1 ⋅ sin φ2 + cos φ1 ⋅ cos φ2 ⋅ cos Δλ ) ⋅ R
Javascript:
varφ1= lat1.toRadians(),φ2= lat2.toRadians(),Δλ=(lon2-lon1).toRadians(), R =6371e3;// gives d in metres var d =Math.acos(Math.sin(φ1)*Math.sin(φ2)+Math.cos(φ1)*Math.cos(φ2)*Math.cos(Δλ))* R;
Equirectangular approximation
If performance is an issue and accuracy less important, for small distances Pythagoras’ theorem can be used on an equirectangular projection:*
Formula |
x = Δλ ⋅ cos φm |
y = Δφ | |
d = R ⋅ √x² + y² | |
JavaScript: |
var x =(λ2-λ1)*Math.cos((φ1+φ2)/2); var y =(φ2-φ1); var d =Math.sqrt(x*x + y*y)* R;
|
λ2就是lon2
λ1就是lon1
角度和弧度换算的原理:
网址: https://tianyelina.iteye.com/blog/756031
Javascript实现(根据原理自己实现也很容易):
网址: https://www.w3resource.com/javascript-exercises/javascript-math-exercise-33.php
相关推荐
最近发现2018年12月4日上传的转换工具中所用的阿里云地图接口失效了(请管理员将其删除),这次换用百度地图接口(始终保留坐标位置名称显示的原因主要是为了直观验证转换是否靠谱),取消批量转换(主要是为了减小...
靠谱助手使用方法.docx
面试总结js 靠谱靠谱靠谱.md
安卓模拟器社区(靠谱社区)是中国最大的安卓模拟器交流论坛,下载靠谱助手安卓模拟器可在PC电脑上极速运行安卓手游和应用。最全手机游戏电脑版攻略心得!
靠谱助手是世界最大的安卓模拟器。内有百万应用可供你下载!
手机ime串号简介以及靠谱查询网站方法.pdf
读《马克思靠谱》心得.pdf
全网最靠谱的计算工作时间函数(自动剔除非工作时间),自己网上找的各种出错后来逼得没办法自己写了一个。 可以计算工作时间的函数,自动去除非工作时间。还可以微调函数修改作息时间。自动去除节假日中午休息时间...
靠谱助手安卓PC模拟器
靠谱手机安卓应用助手,海量应用随便下载,实用、好用。
读《马克思靠谱》心得参考.doc
靠谱助手是一款专业的第三方智安卓模拟器管理软件,软件由靠谱社区推出,目前支持bluestacks安卓模拟器,是国内最完美的PC端管理软件以及最大用户群体的安卓模拟器管理软件。软件支持安卓的APP资源搜索、下载、APP...
我在CSDN总结的一些比较靠谱的比较靠的4个项目希望能帮到大家。
简单实用的文件分割工具,可以轻松一键把比较大的文件分割成几个小的文件。资源里包含两个工具,一个是我的同学自己写的,比较简单但是绝对靠谱。另一个是偶然找到的,也是好使的。资源里配有使用说明,请放心下载。
java面试题整理打包 最新 最全 靠谱 java 面试 试题 试卷 面试题 整理
ios面试题,招聘一个靠谱ios开发答案 ios面试题,招聘一个靠谱ios开发答案
锅炉课程设计计算软件 超级靠谱好用 李加护版本课程设计必备
靠谱助手
网站seo百度排名优化网站推广靠谱的公司推荐.docx网站seo百度排名优化网站推广靠谱的公司推荐.docx网站seo百度排名优化网站推广靠谱的公司推荐.docx网站seo百度排名优化网站推广靠谱的公司推荐.docx网站seo百度排名...
2019商场“不靠谱”菜馆主题活动策划方案【餐饮】【活动策划】