views:

64

answers:

3

I came across this when I did a search on SO: http://stackoverflow.com/questions/518026/zip-code-to-city-state-and-vice-versa-in-a-database

But I'm wondering, why can't we just use the Maps APIs for this? Has anyone tried doing this?

A: 

It's pretty easy to use the Geonames webservice apis for this, specifically the postalCodeSearch method. Works great in my experience unless you're issuing multiple queries/second, although caching results is generally worthwhile. (ie: they do not change frequently.)

corprew
+1  A: 

use the google maps api Geocoder

Sky Sanders
+1  A: 

Yes, it's pretty easy to do it with Google Maps Geocoding getLocations().

<html>
  <head>
    <meta http-equiv="content-type" content="text/html; charset=utf-8"/>
    <title>Geocoding example</title>
    <script src="http://maps.google.com/maps?file=api&amp;v=2" type="text/javascript"></script>
    <script type="text/javascript">
   var geocoder;
   var map;
   var address = "10001"; //NEW YORK zip
   function load()
   {
      map = new GMap2(document.getElementById("map"));
      geocoder = new GClientGeocoder();
      geocoder.getLocations(address, addToMap);
   }
   function addToMap(response)
   {
      place = response.Placemark[0];
      point = new GLatLng(place.Point.coordinates[1],place.Point.coordinates[0]);
      map.setCenter(point, 13);
      marker = new GMarker(point);
      map.addOverlay(marker);
      marker.openInfoWindowHtml(place.address);
   }
  </script>
  </head>
  <body onload="load()" onunload="GUnload()">
    <div id="map" style="width: 500px; height: 500px"></div>
  </body>
</html>

You could give it a try online on Google code playground.
Have fun!

systempuntoout