【问题标题】:Calculation of proximity between of one location to many other locations计算一个位置与许多其他位置之间的接近度
【发布时间】:2012-07-18 05:44:52
【问题描述】:

我有一个包含经纬度列表的数据库

-DeviceName
-Latitude
-Longitude

鉴于我当前设备的纬度和经度,我想获取数据库列表中距离/接近 X 公里的所有设备。

如何计算我所在位置与其他位置的距离?

【问题讨论】:

  • 您是否正在考虑进行 SQL 查询?
  • 是的,我想做一个 SQL 查询

标签: c# php math geolocation proximity


【解决方案1】:

我想你想看看这个amazing presentation。它会告诉你如何使用(并解释加分!)haversine formula 来计算地球表面上的距离,考虑曲率以及如何避免数据库查询中的一些常见错误等。他的数据集非常准确你的是什么 - 项目,经度和纬度。

【讨论】:

    【解决方案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);
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2017-04-20
      • 1970-01-01
      • 2013-06-02
      • 2017-01-13
      • 2011-12-28
      • 1970-01-01
      • 2020-11-27
      相关资源
      最近更新 更多