SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Evangelist smftre's Avatar
    Join Date
    Dec 2008
    Location
    London
    Posts
    436
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Question Get nearest postcode from another postcode according to distance..

    Hello guys and gals!

    I am almost complete with another site but have a feature left that I still need to do, basically it entails the following:

    • There are entries stored in a MySQL database, and each entry has a postcode.
    • The user uses a "search form" and enters their postcode and selects a distance from a dropdown, the values are "Any, 1mile, 5miles, 10miles, 100miles".
    • The user hits the search button and a SQL query is executed and returns all entries in the database which have the above distance from the above postcode.

    Anyone know how to achieve this?

    I have Googled around and found a few solutions but they aren't exactly what I'm looking for, they all seem to be about determining the distance between 2 given postcodes.
    My script is quite different as you can see..

    Any thoughts, comments or "full on solutions" are very very welcome
    Statvoo.com The Website Traffic Monitor
    The best way to monitor traffic to your sites for free!


    Web Development London UK We make web 3.0 applications

  2. #2
    SitePoint Wizard silver trophybronze trophy Cups's Avatar
    Join Date
    Oct 2006
    Location
    France, deep rural.
    Posts
    6,869
    Mentioned
    17 Post(s)
    Tagged
    1 Thread(s)
    If you know my postcode, then you also know my postcode location (lat, lng).

    If I now want to search for Garden Centres (or whatever) whose location (lat, lng) falls inside a circle then you are going to want an sql search like this one.

    If this is just a bell or a whistle on the website you are developing, then you should be fine.

    If it turns out that this is generating a lot of traffic (and server-side computations) then seriously consider using Mysql's native spatial abilities by not simply storing lat, lng pairs but POINT(x,y) as well. You should get selects a lot quicker using mysql spatial point -- but as I say, don't bother unless you see proof that you need to learn this -- unless it turns you on of course ...

  3. #3
    SitePoint Evangelist smftre's Avatar
    Join Date
    Dec 2008
    Location
    London
    Posts
    436
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    @Cups, thanks for your comments, I am currently taking a look at the post you referred to!
    If anyone else has anything to add, oh please do
    Statvoo.com The Website Traffic Monitor
    The best way to monitor traffic to your sites for free!


    Web Development London UK We make web 3.0 applications


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •