SQL Query For Total Points Within Radius of a Location

前端 未结 3 1296
醉酒成梦
醉酒成梦 2021-02-11 07:27

I have a database table of all zipcodes in the US that includes city,state,latitude & longitude for each zipcode. I also have a database table of points that each have a lat

3条回答
  •  孤城傲影
    2021-02-11 08:14

    When I do these type of searches, my needs allow some approximation. So I use the formula you have in your second query to first calculate the "bounds" -- the four lat/long values at the extremes of the allowed radius, then take those bounds and do a simple query to find the matches within them (less than the max lat, long, more than the minimum lat, long). So what I end up with is everything within a square sitting inside the circle defined by the radius.

提交回复
热议问题