SitePoint Sponsor

User Tag List

Results 1 to 9 of 9
  1. #1
    SitePoint Evangelist webchalkboard's Avatar
    Join Date
    Jan 2005
    Location
    Bristol, UK
    Posts
    494
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Working out distances between places in a directory

    Hi,

    I have a client who wants to have a directory with a search function and in the results they want to show the distance of the searcher from the various entries in the database.

    So they say you are 2 miles from person a and 2.2 miles from person b.

    How can I do this? I guess I need to plug into some kind of api and use long/lat cordinates? Any pointers would be great.

    Thanks,
    Tom
    Websites for Sale - Sell websites in a purpose built marketplace
    Then do some Shopping

  2. #2
    SitePoint Member lisaanne's Avatar
    Join Date
    Jul 2007
    Location
    Bristol, UK
    Posts
    19
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Ooh - there was another reply here a minute ago but it's gone now. The other reply was directing webchalkboard to MaxMind but I was just going to say that I don't think this is quite what you need.

    MaxMind and ones like it are all about IP addresses which is nothing to do with what you need. The demo on the MaxMind site says "To find countries and cities, enter IP addresses/hostnames, separated by spaces:" and comes back with all kinds of ISP stuff. And was all American.

  3. #3
    Follow Me On Twitter: @djg gold trophysilver trophybronze trophy Dan Grossman's Avatar
    Join Date
    Aug 2000
    Location
    Philadephia, PA
    Posts
    20,580
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by lisaanne View Post
    MaxMind and ones like it are all about IP addresses which is nothing to do with what you need. The demo on the MaxMind site says "To find countries and cities, enter IP addresses/hostnames, separated by spaces:" and comes back with all kinds of ISP stuff. And was all American.
    I only removed it because the accuracy was about 60% to city-level for the UK, not because it wasn't a viable solution.

    MaxMind's GeoIP City database maps cities and postal codes to lat/long as well as IP addresses. So it could not only tell the site where the current visitor is, but also where something in the directory is if you have its IP, city or postal code. That's all the info you need to compute the distances.

    You could use that database to power a store locator for a US retail chain, for example. It has all the data to compute the distance between the visitor (by IP) and all of the stores (by the zip code of their address).

    But again, MaxMind's DB isn't accurate enough for the UK.

  4. #4
    SitePoint Member lisaanne's Avatar
    Join Date
    Jul 2007
    Location
    Bristol, UK
    Posts
    19
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Oh right, thanks! So if it was - or if you were doing it for the US - how do you compute the distances?! Dumb question I'm sure I could work out if I studied it.

  5. #5
    Follow Me On Twitter: @djg gold trophysilver trophybronze trophy Dan Grossman's Avatar
    Join Date
    Aug 2000
    Location
    Philadephia, PA
    Posts
    20,580
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by lisaanne View Post
    Oh right, thanks! So if it was - or if you were doing it for the US - how do you compute the distances?! Dumb question I'm sure I could work out if I studied it.
    You compute it from the two latitude/longitude pairs using a spherical distance formula

    http://www.mathforum.com/library/drmath/view/51711.html
    http://en.wikipedia.org/wiki/Haversine_formula


    Off Topic:

    I used to work for MathForum.com and still live a 10 minute walk from their office

  6. #6
    SitePoint Member lisaanne's Avatar
    Join Date
    Jul 2007
    Location
    Bristol, UK
    Posts
    19
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    haha - aren't you exactly the right person for this thread! Cool, thanks! Lx

  7. #7
    SitePoint Evangelist webchalkboard's Avatar
    Join Date
    Jan 2005
    Location
    Bristol, UK
    Posts
    494
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks for all the replies, I think we might have cracked it.

    Here are the links we've found for other people's reference.

    To do it by outcode:
    http://www.sloomedia.com/php_postcode_script.php

    To do it using Google Maps:
    http://groups.google.com/group/Googl...194df76f?pli=1

    Thanks,
    Tom
    Websites for Sale - Sell websites in a purpose built marketplace
    Then do some Shopping

  8. #8
    Follow Me On Twitter: @djg gold trophysilver trophybronze trophy Dan Grossman's Avatar
    Join Date
    Aug 2000
    Location
    Philadephia, PA
    Posts
    20,580
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by webchalkboard View Post
    Thanks for all the replies, I think we might have cracked it.

    Here are the links we've found for other people's reference.

    To do it by outcode:
    http://www.sloomedia.com/php_postcode_script.php

    To do it using Google Maps:
    http://groups.google.com/group/Googl...194df76f?pli=1

    Thanks,
    Tom
    Make sure your client gets his/her attorney to review the Google Maps API terms of service if you're going to use that. It is a breach of those terms, for example, to use the data without displaying a Google Map, to pre-fetch the geocoding data in a non-limited non-temporary manner, to use the data anywhere not accessible to the public, and a bunch of other things that you might be thinking of doing.

  9. #9
    SitePoint Evangelist webchalkboard's Avatar
    Join Date
    Jan 2005
    Location
    Bristol, UK
    Posts
    494
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks very much for the heads up.
    Websites for Sale - Sell websites in a purpose built marketplace
    Then do some Shopping


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
  •