Win a copy of Modern JavaScript for the Impatient this week in the Server-Side JavaScript and NodeJS forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Bear Bibeault
  • Junilu Lacar
Sheriffs:
  • Jeanne Boyarsky
  • Tim Cooke
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • salvin francis
  • Frits Walraven
Bartenders:
  • Scott Selikoff
  • Piet Souris
  • Carey Brown

Zip Code Search API

 
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?
 
Rancher
Posts: 4686
7
Mac OS X VI Editor Linux
  • 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.
     
    WHAT is your favorite color? Blue, no yellow, ahhhhhhh! Tiny ad:
    Thread Boost feature
    https://coderanch.com/t/674455/Thread-Boost-feature
      Bookmark Topic Watch Topic
    • New Topic