|
|
Question : Return records within givin radius of postcode or area
|
|
Dear Experts
We manage a large estate agency website. The SQL 2005 property database contains full information about each of the individual properties we have for sale - including postcode, area, latitude and longitude coordinates.
We would to offer the users the ability to search by entering an area or postcode and then another form field where they can select the radius (ie 1 mile, 2 miles etc etc etc). What we would like to return are all properties that fall within the radius they have selected.
I appreciate there are 3rd party software solutions out there that could perhaps help with this, however I wondered if anyone can offer any assistance (or advise if its possible) to achieve this without making what will no doubt be a large investment in 3rd party services/data.
Thanks for any help
|
Answer : Return records within givin radius of postcode or area
|
|
Just to push rweil's comment: the formulas are for general use. In your precise case, you are looking at points that are within a certain distance of your "target", and you might consider without a great loss precision that the distance is the square root of A x (delta of latitudes)^2 + B x (delta of longitudes)^2 where the "constants" A and B will be computed for the target point (thus these "constants" will change with the target coordinates, more precisely with its latitude). So you should 1 - compute A and B from the target latitude 2 - compute from that the maximum delta for latitude and for longitude 3 - restrict your sql query to the "square" defined in 2/ above I would personnally prefer extratct all possible candidates, and then for each of them compute the distance, rather than issuing a single SQL query where the formula would be computed for each record
|
|
|
|
|