Fastest Way to Find Distance Between Two Lat/Long Points

后端 未结 15 1008
时光说笑
时光说笑 2020-11-21 10:12

I currently have just under a million locations in a mysql database all with longitude and latitude information.

I am trying to find the distance between one point a

15条回答
  •  星月不相逢
    2020-11-21 10:29

    set @latitude=53.754842;
    set @longitude=-2.708077;
    set @radius=20;
    
    set @lng_min = @longitude - @radius/abs(cos(radians(@latitude))*69);
    set @lng_max = @longitude + @radius/abs(cos(radians(@latitude))*69);
    set @lat_min = @latitude - (@radius/69);
    set @lat_max = @latitude + (@radius/69);
    
    SELECT * FROM postcode
    WHERE (longitude BETWEEN @lng_min AND @lng_max)
    AND (latitude BETWEEN @lat_min and @lat_max);
    

    source

提交回复
热议问题