【问题标题】:sql query for map , lat , long distances giving illogical distance resultsql查询地图,纬度,长距离给出不合逻辑的距离结果
【发布时间】:2014-11-20 08:51:03
【问题描述】:

我正在尝试通过我的数据库中的查询来获取与地图点的距离。 我用它来计算公里数。

  SELECT title_fr,
         type,
         property_type,
         price,
         longi,
         lat, 
         ( 6371 * acos ( cos ( radians(10.811812877) ) * cos( radians( lat ) ) * cos( radians( longi ) - radians(36.461330195) ) + sin ( radians(10.811812877) ) * sin( radians( lat ) ) ) ) AS distance 
    FROM skopeo_annonce_immo 
ORDER BY distance

我的变量是:

latitude = 10.811812877
longitude = 36.461330195

我的问题是查询给出了错误的距离计算结果。例如给出3841.9933722712412 的距离 当我的数据库中的纬度和经度与我的查询中用作参数的相同时,作为距离结果而不是 0。 其他结果是不连贯的,它们给我的距离太大了。

title_fr                      type       property_type price      longi          lat             distance 
Villa avec picsine très...    to_sell    home          640000     11.035560071   33.825791858    3637.6770884050457
Belle maison à vendre         to_sell    home          192600     10.8492136     33.866210798    3653.92943440657
villa meublée a louer         to_rent    furnished     3000       10.70034027    34.774895801    3728.0785739669286
terrain à reougeb             to_sell    land          70         9.0293884277   33.449776583    3760.4640127561815
Appartement La Plage          to_rent    home          300        10.811812877   36.461330195    3841.9933722712412
Terrain Adel                  to_sell    land          270        10.809098482   36.462822475    3842.2851686112595
Appartement Maamoura          to_sell    apartment     180000     10.801491737   36.466369224    3843.056144544567
Dar  Maamoura Club            to_sell    home          400000     10.801513195   36.466403736    3843.057245114819
DAR L'ELEGANTE                to_sell    home          645000     10.82118988    36.485348924    3843.1331942217366

距离在最后一列。 我已经尝试过其他公式,它也给了我错误的结果。

更新和解决方案

有时解决方案很简单,我使用的计算距离的公式是正确的。 问题是我已经反转了变量! 正确的顺序应该是这样。

latitude = 36.461330195
longitude = 10.811812877

然后就好了。

【问题讨论】:

    标签: mysql sql google-maps distance latitude-longitude


    【解决方案1】:

    我想问题可能是由于您的坐标投影不正确?你用的是哪个投影? (我相信谷歌地图是球形墨卡托)。

    如果您无法使查询正常工作,另一种解决方案是使用内置距离计算器的 maps api:

    var distance = google.maps.geometry.spherical.computeDistanceBetween(latLong, latLong);
    

    您可以在客户端的 foreach 循环中轻松执行此操作,从而为您提供所需的距离。

    For reference.

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2014-03-01
      • 2018-06-04
      • 2015-08-14
      • 2015-07-16
      • 2017-07-03
      • 2016-08-29
      • 2014-01-01
      • 1970-01-01
      相关资源
      最近更新 更多