Postcode Search

How do you make a postcode search? I want to locate stores by entering a postcode then a radius.
:)




You need to get hold of a list of all the Australian Postcodes with thier longitudes and latitudes. I downloaded something here: http://www.communicatemedia.com.au/postcodes.php You'll have to import all that CSV into a table.

You'll need to run some trig calulations on to work out which postcodes fall within the radius.

Something like this:


SELECT DISTINCT storeId, storeName, Address, Suburb, State, Postcode, Phone, Fax,
(ACOS((SIN(RADIANS(p1.Latitude)) * SIN(RADIANS(p2.Latitude)))
+ (COS(RADIANS(p1.Latitude)) * COS(RADIANS(p2.Latitude))
* COS(ABS(RADIANS(p1.Longitude) - RADIANS(p2.Longitude))))) * 6367) AS theDist
FROM postcodes p1
INNER JOIN stores s ON p1.PostCodeNumber = s.postcode, postcodes p2
WHERE ((ACOS((SIN(RADIANS(p1.Latitude)) * SIN(RADIANS(p2.Latitude)))
+ (COS(RADIANS(postcodes1.Latitude)) * COS(RADIANS(p2.Latitude))
* COS(ABS(RADIANS(p1.Longitude) - RADIANS(p2.Longitude))))) * 6367) <= $radius) AND
(p2.PostCodeNumber = $postcode) ORDER BY s.Suburb, s.StoreName

-
That query probably won't run without a little debugging

It's unlikely that the postcode geolocations will be 100% accurate. I think from memory there are about 16000 postcodes in Australia and not all the coordinates will be right.

Thanks! I think I can get this running.

I have a product available

I have a product available at http://www.dreamscapemedia.com.au/products/aus_postcode_locator/index.php for AUD $165 that will let you do this.

Googpel Maps API

The Google maps API has a geo converter thingy that will take an Address and convert it into a Latitude and Longitude. I don't know how you'd go about converting everything.

Post new comment

  • Web page addresses and e-mail addresses turn into links automatically.
  • Allowed HTML tags: <a> <em> <strong> <cite> <code> <ul> <ol> <li> <dl> <dt> <dd>
  • Lines and paragraphs break automatically.

More information about formatting options