<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/css" href="/stylesheets/rss.css"?>
<rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:trackback="http://madskills.com/public/xml/rss/module/trackback/">
  <channel>
    <title>Segment7: Geocoding Goodness</title>
    <link>http://blog.segment7.net/articles/2006/06/13/geocoding-goodness</link>
    <language>en-us</language>
    <ttl>40</ttl>
    <description>The Blog</description>
    <item>
      <title>Geocoding Goodness</title>
      <description>&lt;p&gt;I've implemented ruby bindings for the three major geocoding APIs as gems:

&lt;table&gt;
&lt;tr&gt;&lt;th&gt;API&lt;th&gt;gem name
&lt;tr&gt;&lt;td&gt;Yahoo!&lt;td&gt;&lt;tt&gt;yahoo-geocode&lt;/tt&gt;
&lt;tr&gt;&lt;td&gt;Google&lt;td&gt;&lt;tt&gt;google-geocode&lt;/tt&gt;
&lt;tr&gt;&lt;td&gt;geocoder.us&lt;td&gt;&lt;tt&gt;geocoder-us&lt;/tt&gt;
&lt;/table&gt;

&lt;p&gt;And as a bonus, you get a Yahoo! search gem to search either the web or for locations, &lt;tt&gt;yahoo-search&lt;/tt&gt;.

&lt;p&gt;The bindings all have similar APIs, but return different objects depending upon what information the API reliably provides.  Yahoo! gives the most information, followed by Google, followed by geocoder.us.

&lt;h3&gt;Yahoo!&lt;/h3&gt;

&lt;p&gt;&lt;a href="http://dev.robotcoop.com/Libraries/yahoo-geocode/index.html"&gt;documentation&lt;/a&gt;

&lt;pre&gt;&lt;code&gt;require 'rubygems'
require 'yahoo/geocode'

yg = Yahoo::Geocode.new application_id
locations = yg.locate '701 First Street, Sunnyvale, CA'
p location.first.coordinates&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;(and searching for locations)

&lt;p&gt;&lt;a href="http://dev.robotcoop.com/Libraries/yahoo-search/index.html"&gt;documentation&lt;/a&gt;

&lt;pre&gt;&lt;code&gt;require 'rubygems'
require 'yahoo/local_search'

yls = Yahoo::LocalSearch.new application_id
results, = yls.locate 'pizza', 94306, 2
results.each do |location|
  puts "#{location.title} at #{location.address}, #{location.city}"
end&lt;/code&gt;&lt;/pre&gt;

&lt;h3&gt;Google&lt;/h3&gt;

&lt;p&gt;&lt;a href="http://dev.robotcoop.com/Libraries/google-geocode/index.html"&gt;documentation&lt;/a&gt;

&lt;pre&gt;&lt;code&gt;require 'rubygems'
require 'google_geocode'

gg = GoogleGeocode.new application_id
location = gg.locate '1600 Amphitheater Pkwy, Mountain View, CA'
p location.coordinates&lt;/code&gt;&lt;/pre&gt;

&lt;h3&gt;geocoder.us&lt;/h3&gt;

&lt;a href="http://dev.robotcoop.com/Libraries/geocoder-us/index.html"&gt;documentation&lt;/a&gt;

&lt;pre&gt;&lt;code&gt;require 'rubygems'
require 'geocoder_us'

gu = GeocoderUs.new 'username', 'password'
p gu.locate('1924 E Denny Way, Seattle, WA')&lt;/code&gt;&lt;/pre&gt;
</description>
      <pubDate>Tue, 13 Jun 2006 15:01:00 -0700</pubDate>
      <guid isPermaLink="false">urn:uuid:e5220010-f11d-4c99-af62-be1528c8bbfd</guid>
      <author>drbrain@segment7.net (Eric Hodel)</author>
      <link>http://blog.segment7.net/articles/2006/06/13/geocoding-goodness</link>
      <category>Ruby</category>
      <category>Software</category>
    </item>
    <item>
      <title>"Geocoding Goodness" by Eric Hodel</title>
      <description>&lt;p&gt;You want to use exception handling.  This is covered in the &lt;a href="http://www.rubycentral.com/book/tut_exceptions.html" rel="nofollow"&gt;Pickaxe 1st Ed&lt;/a&gt; and in &lt;a href="http://poignantguide.net/ruby/chapter-5.html" rel="nofollow"&gt;chapter 5&lt;/a&gt; and &lt;a href="http://poignantguide.net/ruby/chapter-6.html" rel="nofollow"&gt;chapter 6&lt;/a&gt; of Why&amp;#8217;s (Poignant) Guide.&lt;/p&gt;


	&lt;p&gt;If you&amp;#8217;re calling it from a controller you&amp;#8217;d write something like this:&lt;/p&gt;


	&lt;pre&gt;&lt;code&gt;def lookup
  gg = GoogleGeocode.new GOOGLE_APP_ID
  location = gg.lookup params[:address]
  # do whatever it is you would do
rescue GoogleGeocode::AddressError
  flash[:message] = "I'm sorry, I couldn't find #{params[:address]}" 
end&lt;/code&gt;&lt;/pre&gt;</description>
      <pubDate>Tue, 04 Jul 2006 00:03:57 -0700</pubDate>
      <guid isPermaLink="false">urn:uuid:2a02929b-b14b-4a8e-ac25-36cff6031335</guid>
      <link>http://blog.segment7.net/articles/2006/06/13/geocoding-goodness#comment-266</link>
    </item>
    <item>
      <title>"Geocoding Goodness" by Damon Brodie</title>
      <description>&lt;p&gt;Hi I&amp;#8217;m a new rails user, so please go easy on me.  I&amp;#8217;ve got the google_geocode working, but I don&amp;#8217;t know how to deal with the unknown address exceptions.  Can you post some sample code for dealing with that?&lt;/p&gt;


	&lt;p&gt;Thanks!&lt;/p&gt;


	&lt;p&gt;Damon&lt;/p&gt;</description>
      <pubDate>Mon, 03 Jul 2006 20:02:08 -0700</pubDate>
      <guid isPermaLink="false">urn:uuid:339e3e9a-e617-4ecf-b9e2-8ae611b6e13e</guid>
      <link>http://blog.segment7.net/articles/2006/06/13/geocoding-goodness#comment-264</link>
    </item>
  </channel>
</rss>
