【问题标题】:Calculation of proximity between of one location to many other locations计算一个位置与许多其他位置之间的接近度
【发布时间】:2012-07-18 05:44:52
【问题描述】:
我有一个包含经纬度列表的数据库
-DeviceName
-Latitude
-Longitude
鉴于我当前设备的纬度和经度,我想获取数据库列表中距离/接近 X 公里的所有设备。
如何计算我所在位置与其他位置的距离?
【问题讨论】:
标签:
c#
php
math
geolocation
proximity
【解决方案2】:
如果您追求原始代码,这应该会对您有所帮助:
private static Double rad2deg(Double rad) {
return (rad / Math.PI * 180.0);
}
private static Double deg2rad(Double deg) {
return (deg * Math.PI / 180.0);
}
private const Double kEarthRadiusKms = 6376.5;
private static Double CalculateDistance(Double latitude1, Double longitude1, Double latitude2, Double longitude2) {
double theta = longitude1 - longitude2;
double dist = Math.Sin(deg2rad(latitude1)) * Math.Sin(deg2rad(latitude2)) + Math.Cos(deg2rad(latitude1)) * Math.Cos(deg2rad(latitude2)) * Math.Cos(deg2rad(theta));
dist = Math.Acos(dist);
dist = rad2deg(dist);
dist = dist * 60 * 1.1515;
dist = dist * 1.609344;
return (dist);
}