我试图计算谷歌地图中两点之间的距离.我发现他们正在使用的某些链接
distanceTo()以及使用它计算的某个地方distanceBetween().哪个最好计算距离?
此链接可能对您有帮助。
\n\n它允许计算两个纬度经度点之间的距离:
\n\n此脚本使用 \xe2\x80\x98Haversine\xe2\x80\x99 公式计算两点之间的大圆距离(即地球\xe2\x80\x99s 表面上的最短距离)。
\n\nvar R = 6371; // Radius of the earth in km\nvar dLat = (lat2-lat1).toRad(); // Javascript functions in radians\nvar dLon = (lon2-lon1).toRad(); \nvar a = Math.sin(dLat/2) * Math.sin(dLat/2) +\n Math.cos(lat1.toRad()) * Math.cos(lat2.toRad()) * \n Math.sin(dLon/2) * Math.sin(dLon/2); \nvar c = 2 * Math.atan2(Math.sqrt(a), Math.sqrt(1-a)); \nvar d = R * c; // Distance in km.\nRun Code Online (Sandbox Code Playgroud)\n
| 归档时间: |
|
| 查看次数: |
1073 次 |
| 最近记录: |