日韩av黄I国产麻豆传媒I国产91av视频在线观看I日韩一区二区三区在线看I美女国产在线I麻豆视频国产在线观看I成人黄色短片

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 >

已知两点的经度和纬度,计算两点间的距离(php,javascript)

發布時間:2025/4/16 66 豆豆
生活随笔 收集整理的這篇文章主要介紹了 已知两点的经度和纬度,计算两点间的距离(php,javascript) 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

php代碼:轉載  http://www.cnblogs.com/caichenghui/p/5977431.html

1 /** 2 * 求兩個已知經緯度之間的距離,單位為米 3 * 4 * @param lng1 $ ,lng2 經度 5 * @param lat1 $ ,lat2 緯度 6 * @return float 距離,單位米 7 * @author www.Alixixi.com 8 */ 9 function getdistance($lng1, $lat1, $lng2, $lat2) { 10 // 將角度轉為狐度 11 $radLat1 = deg2rad($lat1); //deg2rad()函數將角度轉換為弧度 12 $radLat2 = deg2rad($lat2); 13 $radLng1 = deg2rad($lng1); 14 $radLng2 = deg2rad($lng2); 15 $a = $radLat1 - $radLat2; 16 $b = $radLng1 - $radLng2; 17 $s = 2 * asin(sqrt(pow(sin($a / 2), 2) + cos($radLat1) * cos($radLat2) * pow(sin($b / 2), 2))) * 6378.137 * 1000; 18 return $s; 19 }

javascript代碼:

1 //返回單位 m 2 get_distance(lat1,lng1,lat2,lng2){ 3 var radLat1 = lat1 * Math.PI / 180.0; 4 var radLat2 = lat2 * Math.PI / 180.0; 5 var a = radLat1 - radLat2; 6 var b = lng1 * Math.PI / 180.0 - lng2 * Math.PI / 180.0; 7 var s = 2 * Math.asin(Math.sqrt(Math.pow(Math.sin(a / 2), 2) + Math.cos(radLat1) * Math.cos(radLat2) * Math.pow(Math.sin(b / 2), 2))); 8 s = s * 6378.137; 9 s = Math.round(s * 10000) / 10000; 10 s = s*1000; 11 return s; 12 },

?

轉載于:https://www.cnblogs.com/zhuchenglin/p/7705348.html

總結

以上是生活随笔為你收集整理的已知两点的经度和纬度,计算两点间的距离(php,javascript)的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。