How to implement proximity search with postcode?
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-a开发者_开发知识库dd-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
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.
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.
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 | |
+----------+----------------------+------+-----+---------+-------+
精彩评论