MySQL最接近匹配两列

时间:2014-05-08 09:58:30

标签: mysql

我有一个数十万纬度/经度的数据库。我试图将纬度/经度与最近点匹配。我一直在使用hasrsine公式,但它很慢。因为我有高密度的数据,我宁愿匹配最接近纬度和经度列。目前我有这个:

SELECT `ward`, ACOS(
      COS(RADIANS( `staging_gps_names`.latitude ))
    * COS(RADIANS( 51.5189698 ))
    * COS(RADIANS( `staging_gps_names`.longitude ) - RADIANS(  -0.1265003 ))
    + SIN(RADIANS( `staging_gps_names`.latitude ))
    * SIN(RADIANS( 51.5189698 ))
       )*3958.82 AS distance_miles
FROM `staging_gps_names` 
WHERE `staging_gps_names`.latitude BETWEEN 51.52 AND 51.50
ORDER BY distance_miles ASC 
LIMIT 1

理想情况如上所述,考虑到我所拥有的纬度/经度的密度,两列上的匹配会更有意义,其中半径距离差异可以忽略不计

0 个答案:

没有答案