当前位置:网站首页>根据经纬度计算距离
根据经纬度计算距离
2022-06-09 01:41:00 【不羁的闰土】
app嵌入百度地图或者高德地图时经常会用到根据经纬度计算距离的方法:
/** * 根据经纬度计算距离的工具类 * Created by leven on 2016/10/8. */
public class Distance {
private static final double EARTH_RADIUS = 6378137.0;
// 返回单位是米
public static double getDistance(double longitude1, double latitude1, double longitude2, double latitude2) {
double Lat1 = rad(latitude1);
double Lat2 = rad(latitude2);
double a = Lat1 - Lat2;
double b = rad(longitude1) - rad(longitude2);
double 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 * EARTH_RADIUS;
s = Math.round(s * 10000) / 10000;
return s;
}
private static double rad(double d) {
return d * Math.PI / 180.0;
}
}边栏推荐
- 2022-06-08:找到非负数组中拥有“最大或的结果“的最短子数组,返回最短长度。
- Explication détaillée du nombre de points flottants (une étude approfondie du nombre de points flottants)
- Version number ^ and~
- Notes on supporting geo data mining live broadcast of Shengxin skill tree
- Official account mall system makes e-commerce easier!
- I have read many tutorials, but I still can't write a program well. How can I break it?
- Is it safe for Hualong futures to open an account?
- 年轻人“新宠”冷泡茶:能否开启下一个“立顿时代”?
- win10 重命名用户文件夹
- Shell hardware information
猜你喜欢
随机推荐
The best practice of knowledge management in the digital age
日常的周报
GCD Locks Dead cycle SpinLock synchronized
Shell command output
[JS] array de duplication
intel 加速雲數智變革
How Oracle modifies the listening port - stand alone
intel 加速云数智变革
[Niuke SQL] non technical quick start
How MySQL fetches the latest data after grouping
Detailed explanation of floating point numbers (a thorough study of floating point numbers)
How to improve code standardization -- embedded C programming specification.
Laravel基于MongoDB(LBS)实现附近的人、店铺、房源
Notes on supporting geo data mining live broadcast of Shengxin skill tree
Assembly language integrated development environment learning notes
如何提升代码的安全性 —— 代码防御性编程的十条技巧
Win10 rename user folder
GDB notes (10) - check for memory leak, heap overflow, stack overflow, global memory overflow, and continue using after release
数论 --- 朴素筛法、埃氏筛法、线性筛法
How to use mongodb database in laravel framework








