How to efficiently find the closest locations nearby a given location

前端 未结 4 1280
死守一世寂寞
死守一世寂寞 2020-11-27 12:07

I\'m making a script where a load of business are loaded into a mySQL database with a latitude and longitude. Then I am supplying that script with a latitude an longitude (o

4条回答
  •  自闭症患者
    2020-11-27 12:53

    If you have a lot of points, queries with distance formulas in them will be very slow because it's not using an index for the search. For efficiency you'd either have to use a rectangular bounding box to make it faster, or you can use a database with GIS features built in. PostGIS is free and here's an article on doing nearest neighbor search:

    http://www.bostongis.com/PrinterFriendly.aspx?content_name=postgis_nearest_neighbor_generic

提交回复
热议问题