0

Im not sure of the best way for getting what I am after so I will just explain it's application and hope a wiser person than me knows what i am in need of.

I am after something pretty much the same as on www.Autotrader.co.uk where the user enters a full postcode and a search area (radius) from that postcode (1 mile / 10 miles / 100 miles etc) and then only results within the search area are shown.

I wondering how this can be achieved?

Thanks in advance

3 Answers3

0

search by radius... It is easier to search by applying an offset of longitude and latitude, e.g. +/- 0.00001 of the longitude and latitude. But with this approach, the search area will be in rectangle.

Google Maps API can help you with that.

Raptor
  • 53,206
  • 45
  • 230
  • 366
0

Here I will describe a way to achieve your goal: First, I would get the latitude and longitude for each user. You can use the Google Geocode API. Add two columns for latitude and longitude in the table where you store data of the Users. Then, you can calculate the distances between users. This post describes how you dan do that.

Community
  • 1
  • 1
Seb
  • 3
  • 2
0

First, you need to convert Postcode to geographic information, then there is a lot of ways to calculate the distance between two points. So basically:

  1. Using Google's Geocode API to convert postcode to longitude and latitude.
  2. Calculate distance between two points. You can find some information on UK Postcode.

Now, if you are going to search within a database to find out how many relevant points like Autotrader. It is better to pre-cacluate all results and cache them when there is any new point coming. It will provide a faster service and minimize server's load.

James Duan
  • 39
  • 2