• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Zip Code Search API

 
joe black
Ranch Hand
Posts: 103
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I want to implement a zip code search.

The idea is that you enter a zip code to search, and the results contain records where the zipcode is within a certain number of miles from the zip code you entered. I also want to display how many miles the resulting zipcode is from the one you entered.

Is there an api I can use for this?
 
Pat Farrell
Rancher
Posts: 4678
7
Linux Mac OS X VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I haven't found an easy one that does it all.

The basic steps are to:

  • Convert zip code to geocode (place on earth)

  • Since you are talking about Zip codes, I'll assume you are in the US.
  • get the lattitude/longitude of the location.
  • have previously stored all the lat/long values in fields in your records.
  • for each record, calculate distance from record's lat/long to your point



  • The calculation of distance is almost trivial if you use nautical miles, then you can convert it to kilometers, statute miles, etc.

    The US Postal Service has an API you can call to convert addresses to zip codes. They also sell services to convert addresses to zip codes.

    GoogleMaps has some nice APIs that you can use.

    Some databases, I know MySql specifically, have geocoding support, which lets you send a select string and get all records within a radius of a point.

    Once you have it connected, you can have your JSP generate a page using the GoogleMap API to map the points, with zoom, etc. Very cool.
     
    Consider Paul's rocket mass heater.
    • Post Reply
    • Bookmark Topic Watch Topic
    • New Topic