Zip Code Locator

Discussion in 'PHP' started by dprundle, Jan 6, 2009.

  1. #1
    I have 5 businesses located within one state. I'd like for users to be able to enter their zip code and see via google maps how far they are from my businesses.

    Is there a current tool for doing this?
     
    dprundle, Jan 6, 2009 IP
  2. Danltn

    Danltn Well-Known Member

    Messages:
    679
    Likes Received:
    36
    Best Answers:
    0
    Trophy Points:
    120
    #2
    See this entire article: http://code.google.com/apis/maps/documentation/services.html#Geocoding

    It's not particularly hard, hell you can even get directions with a fairly short script. The Google Maps API is fantastic.

    E.g: http://maps.google.com/maps/geo?q=94043&output=xml&sensor=true_or_false&key=abcdefg

    Would get the details for ZIP 94043. This returns the coordinates, once you have these you can use Pythagoras theorem to work out the distance from your businesses. (You do need to enter a Google Map API key though.)

    Dan
     
    Danltn, Jan 6, 2009 IP
  3. dprundle

    dprundle Peon

    Messages:
    399
    Likes Received:
    17
    Best Answers:
    0
    Trophy Points:
    0
    #3
    Thanks, I'll check these out later today.
     
    dprundle, Jan 6, 2009 IP
  4. Th3DarkOn3

    Th3DarkOn3 Peon

    Messages:
    4
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #4
    Or, instead of pythagoras, you can use the Haversine formula. A bit more accurate, as it takes into account earth curavture (Pythagorean Theorum is for a flat space, where as Earth is curved, obviuosly).

    Take a look at http://en.wikipedia.org/wiki/Haversine_formula

    Not sure radius of the Earth, but I know i've used this formula before... You can probably find this fairly easily via Google.



    Good luck.
     
    Th3DarkOn3, Jan 12, 2009 IP