3

I have to use proximity search with postcode for Australia. Going through some links like http://www.randommouse.com/rms/about/product/FNDRY/docs/tutorial/08/how-to-add-google-maps-to-your-review-site-intro.html

I found that I have to manage the the post codes with latitude and longitude if I am not mistaken. But i could not find how to implement this. Can anyone suggest me how to do this with php or give some links so that i could see more on this.

Thanks in advance.

Edited:

I have edited my question:

Can I use google api for this i.e. to get the post codes within given range. I have found a link that is for the drupal. So can I use google api just to get postcodes. The link have followed is http://svendecabooter.be/blog/implementing-location-proximity-search-for-belgium-with-drupal-and-google-maps

user75472
  • 1,277
  • 4
  • 28
  • 53

3 Answers3

3

You'll need to find a database that has the longitude and latitude of each postal code. Once you have the longitude and latitude you'll use the havesine formula (http://www.codecodex.com/wiki/Calculate_Distance_Between_Two_Points_on_a_Globe) to calculate the distance between points. To do a proximity search you'll have to calculate the distance from your starting point to all the points in your dataset. You may also consider using a bounding box and then searching for points inside that bounding box. A geo spatial database like PostGIS has built in functions that can help with all this.

Andrew Hopper
  • 956
  • 2
  • 9
  • 20
  • Thank you Andrew :). One thing is that when we store all the postcodes of Australia in our database i think it will make site slow. Can we use google api for this. Thanks again. – user75472 Dec 02 '09 at 09:14
  • You're welcome. It shouldn't slow your site down all that much. You'll want to keep it on the server and only load the data you need. – Andrew Hopper Dec 04 '09 at 16:31
0

You might also want to look at GeoHash as a way to speed up searching for a long/lat within an area (proximity). There are 'plugins' in various languages eg. GeoHash in Ruby is very easy to use.

Kris
  • 19,188
  • 9
  • 91
  • 111
0

MySQL also provides facility for performing simple Geo distance calculations which may help. https://www.percona.com/blog/2013/10/21/using-the-new-spatial-functions-in-mysql-5-6-for-geo-enabled-applications/

Obtaining up-to-date Australian postcode data can be a problem since AusPost no longer provide the up-to-date list for free. If operating within Google Mapping then it should be OK to populate a table with data taken by querying the Google.

I have a list of suburbs with postcodes and lat/lngs that I use internally that you can download at http://www.computerpros.com.au/data/australian_suburbs.sql

This is a Mysql dump with the following table structure:

+----------+----------------------+------+-----+---------+-------+
| Field    | Type                 | Null | Key | Default | Extra |
+----------+----------------------+------+-----+---------+-------+
| id       | int(10) unsigned     | NO   |     | 0       |       |
| name     | varchar(64)          | NO   |     | NULL    |       |
| postcode | varchar(4)           | NO   |     | NULL    |       |
| state    | smallint(5) unsigned | NO   |     | NULL    |       |
| lat      | float(10,6)          | NO   |     | NULL    |       |
| lng      | float(10,6)          | NO   |     | NULL    |       |
+----------+----------------------+------+-----+---------+-------+
Peter Scott
  • 1,318
  • 12
  • 19