randys.org

Wasting your precious bandwidth since 1999

Google Maps API: Geocoder Fun

So, I’ve been looking into Google maps and the Google maps API recently. It’s a fairly simple JavaScript API that enables one to impliment Google’s maps into a website. The API is in beta but it allows developers (and sites) to use their map interface. The only caveat is that Google doesn’t provide the maping coordinates (i.e. the latitude and longitude).

<p>This caveat can be over come though. Uplon doing a little searching, I came across <a href="http://geocoder.us">geocoder.us</a>, a site that offers a free address to geocode service. You pass them an address, they spit back some coordinates. They run three different interfaces to their service; a <span class="caps">SOAP</span> interface, a <span class="caps">REST</span> interface (which returns a <span class="caps">RDF</span>/XML feed) and an <span class="caps">XML</span>-RPC interface. If you&#8217;re using <span class="caps">PHP</span> &gt;= 4.1.0, you can use <a href="http://www.keithdevens.com/software/xmlrpc/">this handy little script</a> to make an <span class="caps">XML</span>-RPC call to geocoder.us and retrive the results in an array.</p>


<pre><code>require_once('xml_rpc.php');

$rpc_host = ‘rpc.geocoder.us’; $rpc_path = ‘/service/xmlrpc/RPC2′ $result = XMLRPC_request( $rpc_host, $rpc_path, ‘geocode’, array( XMLRPC_prepare(’1600 Amphitheatre Parkway, Mountain View CA 94043′) ) );

<p>This will make the call to the gecoder.us site and return the results as an array (<em>$results</em>)</p>


<pre><code>Array

( [0] => 1 [1] => Array ( [0] => Array ( [number] => 1600 [lat] => 37.423269 [street] => Amphitheatre [state] => CA [zip] => 94043 [city] => Mountain View [suffix] => [long] => -122.082667 [type] => Pky [prefix] => )

<pre><code>)</code></pre>


<pre><code>)</code></pre>


<p>You can then use <em>$result<a href="0">1</a>[&#8216;long&#8217;]</em> and <em>$result<a href="0">1</a>[&#8216;lat&#8217;]</em> to pass into the maps <span class="caps">API</span> and plot a point on the map. Spiffy!</p>


<p>There&#8217;s really only one downside to this: geocoder.us also offers a paid service along side of the free service. What does this mean? It means (and I believe they state it on their site) that they throttle the free service so that the paid service is unaffected. In fact, if you plan on using the service on a for-proffit site or are using their service to make money, you must purchase a license to use the service. It&#8217;s actually reasonably priced for the kind of information you&#8217;re getting. You get 20,000 lookups for $50 <span class="caps">USD</span>.</p>

Geocoding

<p>Geocoder.us also offers the <a href="http://search.cpan.org/~sderle/Geo-Coder-US/">Perl mods</a> that is used to import and query the <a href="http://www.census.gov/geo/www/tiger/tiger2004fe/tgr2004fe.html">2004 <span class="caps">TIGER</span>/Line</a> Census data. With geocoder.us throttling the free service I thought I&#8217;d give the import process and Perl mods a try. I don&#8217;t really recommend trying this unless you really need to&#8230; it&#8217;s kind of a pain in the ass and takes quite a bit of processor power for about 12 hours (on a 1Ghz G4 with 1GB <span class="caps">RAM</span>). I&#8217;m not going to spell everything out for you <a href="http://ian.blenke.com/blog/projects/geocoder/">since it&#8217;s already been done</a>, but I will say that it does work.</p>



<p>Be forewarned. The <span class="caps">TIGER</span>/Line data is around <b>4.5GB</b> of <em>compressed</em> data (which is around <b>25</b> uncompressed). The Geo::Coder::US Perl module chugs through all the zip files and generates a Berkeley DB that&#8217;s around 750MB. Not bad.</p>

Other Geocoding

<p>I did manage to find <a href="http://dan.egnor.name/google.html">another geocoding software</a>, which I assume is what Google is using currently to translate addresses to coordinates since it <a href="http://www.google.com/programming-contest/winner.html">won the 2002 Google Programming Contest</a>. I also got that to compile and import some data. However, I believe that it unzips <em><span class="caps">ALL</span></em> of the <span class="caps">TIGER</span>/Line data files into a temp directory while importing so you&#8217;re gonna need about <b>30GB</b> of free space to use this tool (40GB ro be onthe safe side). I actually ran out of disk space (on my root partition no less) while importing so it never ran completely.</p>



<p>In the end, I ended up scrapping the idea of running a similar service on my web host. Not because I didn&#8217;t have the disk space available (I&#8217;ve got 6GB currently), but because I couldn&#8217;t get the Perl modules to work with the Berkeley DB that was generated on my machine. But, I did play around with <a href="http://geo.randys.org">Google Maps</a>.</p>


<p>Long story short, I wasted about 2 days on something I&#8217;ll probably never use. <span class="caps">JOY</span>!</p>

One Response to “Google Maps API: Geocoder Fun”

  1. [...] Get mapping coordinates from an address Weblog (wiki) | Random Thought (wiki) | Geodata (wiki) -&nbsp;urs @ 14:41:57 randy [1] found a way to get the longitude and latidue out of an address like "1600 Amphitheatre Parkway, Mountain View CA 94043". He uses an XML-RPC call to rpc.geocoder.us and gets an array of mapping coordinates in return. Awesome. As the current petrol prices are rising, I would like to see an SMS service, where you can send something like "Lorraine, Bern" to a certain number and in return you would get an MMS with a map with a red outlined track to the next petrol station with the lowest prices on petrol. [1] http://www.randys.org/content/2005/09/06/google-maps-api-geocoder-fun/ [...]

All content Copyright © Randy Sesser | Hosted by WebFaction
Entries (RSS) | Comments (RSS)