[thelist] Search Engine - Zip codes/postal codes

evolt at weeb.biz evolt at weeb.biz
Wed Dec 1 15:18:20 CST 2004


kent wrote:

> We've all seen web applications that ask the user to enter their
zip/postal codes and then return a set of location based results - a list
based upon nearest geographically proximity. I would like to incorporate
just this kind of functionality into a site. SOooo, anybody here have an
idea about how to go about doing this - tutorials, freeware apps, or the
like?
> Thanks in advance,
> Kent Rygiel
> http://www.kentrygiel.com


I have been investigating implementing this sort of functionality in one of
my sites. And this is what I am going to do:

What you need first is a list of postcodes and grid references. There are
various people who will sell you this information I found
http://www.qas.com/ and http://www.graticule.com/ both have the british
information.

In the UK there is a national grid reference system that is most frequently
used, that basicly gives a location as metres north and east of a
particular point (somewhere south-west of the Scilly Isle if you are at all
interested).
I would imagine most countries have something similar.

Given the eastings of both positions (e1 and e2) and the northings (n1 and
n2) it is simple determine the distance between two point by using
pythagoras

d = √((e1-e2)2 + (n1-n2)2)

So to use this on your site, you would enter the data into a database and
the just use an SQL query to access it. This is the query I would use,
having already entered the grid references of the static locations into the
location table, and having the entire postcode to grid refence table in the
database as gridreference

SELECT location.id, (location.easting -
gridreference.easting)*(location.easting - gridreference.easting) +
(location.northing - gridreference.northing)*(location.northing -
gridreference.northing) as distance_squared
FROM location, gridreference
WHERE gridreference.pc = 'AB12YZ'
order by (location.easting - gridreference.easting)*(location.easting -
gridreference.easting) +  (location.northing -
gridreference.northing)*(location.northing - gridreference.northing)

(I have avoided using sqrt, because that is unneccesary if all we want is
to find the closest, the square of the distance will do fine for that - we
can do the sqrt and other conversions (metres to km and/or miles) on the
output page)

hope this helps
James 

--------------------------------------------------------------------
mail2web - Check your email from the web at
http://mail2web.com/ .




More information about the thelist mailing list