<?xml version="1.0" encoding="UTF-8"?>
<feed xml:lang="en-US" xmlns="http://www.w3.org/2005/Atom">
  <title>opensoul.org - Geocoding as easy as 1-2... Comments</title>
  <id>tag:opensoul.org,2009:/2007/2/13/geocoding-as-easy-as-1-2/comments</id>
  <generator uri="http://mephistoblog.com" version="0.8.0">Mephisto Drax</generator>
  <link href="http://opensoul.org/2007/2/13/geocoding-as-easy-as-1-2/comments.xml" rel="self" type="application/atom+xml"/>
  <link href="/2007/2/13/geocoding-as-easy-as-1-2" rel="alternate" type="text/html"/>
  <updated>2008-11-04T17:08:32Z</updated>
  <entry xml:base="http://opensoul.org/">
    <author>
      <name>Chad</name>
    </author>
    <id>tag:opensoul.org,2007-02-13:1084:9388</id>
    <published>2008-11-04T17:08:32Z</published>
    <updated>2008-11-04T17:08:32Z</updated>
    <category term="Code"/>
    <link href="http://opensoul.org/2007/2/13/geocoding-as-easy-as-1-2" rel="alternate" type="text/html"/>
    <title>Comment on 'Geocoding as easy as 1-2...' by Chad</title>
<content type="html">&lt;p&gt;The folks with the issue of Geocode.geocoder in the environment file:&lt;/p&gt;


	&lt;p&gt;You are likely placing the call inside of the Rails::Initializer.run loop
Place it &lt;span class=&quot;caps&quot;&gt;AFTER&lt;/span&gt;.&lt;/p&gt;</content>  </entry>
  <entry xml:base="http://opensoul.org/">
    <author>
      <name>Daniel</name>
    </author>
    <id>tag:opensoul.org,2007-02-13:1084:6873</id>
    <published>2008-07-22T17:17:41Z</published>
    <updated>2008-07-22T17:17:41Z</updated>
    <category term="Code"/>
    <link href="http://opensoul.org/2007/2/13/geocoding-as-easy-as-1-2" rel="alternate" type="text/html"/>
    <title>Comment on 'Geocoding as easy as 1-2...' by Daniel</title>
<content type="html">&lt;p&gt;I think I may know where the problem is.&lt;/p&gt;


	&lt;p&gt;I was looking at acts_as_geocodable.rb and found:&lt;/p&gt;
	&lt;pre&gt;&lt;code&gt;def to_location
         returning Graticule::Location.new do |location|
do |attr|
             location.send &quot;#{attr}=&quot;, geo_attribute(attr)
           end
         end
       end&lt;/code&gt;&lt;/pre&gt;


	&lt;p&gt;Which has the attributes hard coded in the array. Therefore, if your Model doesn&#8217;t have these exact attributes, then attach_geocode will fail and return nil. As a test, I just created instance methods in my model to return the values of my attributes based on the names in the array and now it works just fine.&lt;/p&gt;


	&lt;p&gt;It seems to be that this was somewhat documented in the &lt;span class=&quot;caps&quot;&gt;README&lt;/span&gt; file and I must have missed it.&lt;/p&gt;


	&lt;p&gt;The problem I have is that my models looks something like this:&lt;/p&gt;


	&lt;p&gt;class Address &amp;lt; ActiveRecord::Base
  belongs_to :postal_code
end&lt;/p&gt;


	&lt;p&gt;class PostalCode &amp;lt; ActiveRecord::Base
  belongs_to :state
end&lt;/p&gt;


	&lt;p&gt;class State &amp;lt; ActiveRecord::Base
  belongs_to :country
end&lt;/p&gt;


	&lt;p&gt;So, if I want to get the zip, city, and state of an address, I need:&lt;/p&gt;


	&lt;p&gt;address.postal_code.zip_code
address.postal_code.state.iso2
address.postal_code.state.country.iso2&lt;/p&gt;


	&lt;p&gt;respectively.&lt;/p&gt;


	&lt;p&gt;If I were to use the recommendations in the &lt;span class=&quot;caps&quot;&gt;README&lt;/span&gt;, how can I do this:&lt;/p&gt;


	&lt;p&gt;class Address &amp;lt; ActiveRecord::Base
  belongs_to :postal_code
  acts_as_geocodable :address =&amp;gt; {:street =&amp;gt; :street1, :locality =&amp;gt; :postal_code.city, :region =&amp;gt; :postal_code.state.iso2, :postal_code =&amp;gt; :postal_code.zip_code }
end&lt;/p&gt;


	&lt;p&gt;That doesn&#8217;t work for me unless instead I just define corresponding instance methods.&lt;/p&gt;


	&lt;p&gt;Any ideas?&lt;/p&gt;


	&lt;p&gt;Thanks&lt;/p&gt;</content>  </entry>
  <entry xml:base="http://opensoul.org/">
    <author>
      <name>Daniel</name>
    </author>
    <id>tag:opensoul.org,2007-02-13:1084:6872</id>
    <published>2008-07-22T15:42:59Z</published>
    <updated>2008-07-22T15:42:59Z</updated>
    <category term="Code"/>
    <link href="http://opensoul.org/2007/2/13/geocoding-as-easy-as-1-2" rel="alternate" type="text/html"/>
    <title>Comment on 'Geocoding as easy as 1-2...' by Daniel</title>
<content type="html">&lt;p&gt;I have the same problem reported about geocoder.nil:&lt;/p&gt;


	&lt;p&gt;NoMethodError: You have a nil object when you didn&#8217;t expect it!
The error occurred while evaluating nil.latitude
    from (irb):6&lt;/p&gt;


	&lt;p&gt;However, this is on &lt;span class=&quot;caps&quot;&gt;OSX&lt;/span&gt; with the latest Rails, Gratitude and ActsAsGeocoder.&lt;/p&gt;


	&lt;p&gt;However, I don&#8217;t think the issue is that Geocode.geocoder is not sticking because when on the same console session I type&lt;/p&gt;


	&lt;p&gt;Geocode.geocoder&lt;/p&gt;


	&lt;p&gt;I does return:&lt;/p&gt;


	&lt;p&gt;=&amp;gt; #, @key=&#8221;my-key&#8221;&lt;/p&gt;


	&lt;p&gt;So, it seems the problem is not related to the &#8220;stickiness&#8221; in environment.rb (neither development nor production). The problem seems to be somewhere in the AR methods added to the model not being able to access Geocode.geocoder.&lt;/p&gt;


	&lt;p&gt;Any clues anyone?&lt;/p&gt;</content>  </entry>
  <entry xml:base="http://opensoul.org/">
    <author>
      <name>skoppy</name>
    </author>
    <id>tag:opensoul.org,2007-02-13:1084:6626</id>
    <published>2008-06-26T16:10:23Z</published>
    <updated>2008-06-26T16:10:23Z</updated>
    <category term="Code"/>
    <link href="http://opensoul.org/2007/2/13/geocoding-as-easy-as-1-2" rel="alternate" type="text/html"/>
    <title>Comment on 'Geocoding as easy as 1-2...' by skoppy</title>
<content type="html">&lt;p&gt;I&#8217;m running into the same problem that John Small is.  Whenever I try to restart the server I get “Unititialized constant Geocode&#8221;&lt;/p&gt;


	&lt;p&gt;I&#8217;ve also tried adding &#8220;require &#8216;graticule&#8217;&#8221; to the environment.rb file as well with no luck.&lt;/p&gt;


	&lt;p&gt;Any help will be greatly appreciated.  Thanks.&lt;/p&gt;</content>  </entry>
  <entry xml:base="http://opensoul.org/">
    <author>
      <name>Brandon</name>
    </author>
    <id>tag:opensoul.org,2007-02-13:1084:6283</id>
    <published>2008-05-28T19:50:14Z</published>
    <updated>2008-05-28T19:50:14Z</updated>
    <category term="Code"/>
    <link href="http://opensoul.org/2007/2/13/geocoding-as-easy-as-1-2" rel="alternate" type="text/html"/>
    <title>Comment on 'Geocoding as easy as 1-2...' by Brandon</title>
<content type="html">&lt;p&gt;John,&lt;/p&gt;


	&lt;p&gt;Did you restart the server? Any time you install a plugin, you need to restart script/server.&lt;/p&gt;</content>  </entry>
  <entry xml:base="http://opensoul.org/">
    <author>
      <name>John Small</name>
    </author>
    <id>tag:opensoul.org,2007-02-13:1084:6181</id>
    <published>2008-05-21T16:53:53Z</published>
    <updated>2008-05-21T16:53:53Z</updated>
    <category term="Code"/>
    <link href="http://opensoul.org/2007/2/13/geocoding-as-easy-as-1-2" rel="alternate" type="text/html"/>
    <title>Comment on 'Geocoding as easy as 1-2...' by John Small</title>
<content type="html">&lt;p&gt;I&#8217;ve installed the latest acts_as_geocodable and the latest Graticule, run the migrations, added the line into environment.rb (in development mode) and It Doesn&#8217;t Work&#8482;.&lt;/p&gt;


	&lt;p&gt;To start checking it works with my models I&#8217;ve uncommented the task in acts_as_geocodeable_tasks.rake, purely as a simple way to load my environment and test a model can become geocodeable. But when the environment loads I get  &#8220;Unititialized constant Geocode&#8221;. Now I&#8217;m a new Rails user so there&#8217;s obviously some Rails idiom which is assumed in the instruction &#8220;just add this to your environment.rb&#8221;, but I don&#8217;t know what it is. Please clue me in, there must be something more I need to add to the environment.rb to get it to work.&lt;/p&gt;</content>  </entry>
  <entry xml:base="http://opensoul.org/">
    <author>
      <name>John</name>
    </author>
    <id>tag:opensoul.org,2007-02-13:1084:5500</id>
    <published>2008-03-18T03:02:59Z</published>
    <updated>2008-03-18T03:02:59Z</updated>
    <category term="Code"/>
    <link href="http://opensoul.org/2007/2/13/geocoding-as-easy-as-1-2" rel="alternate" type="text/html"/>
    <title>Comment on 'Geocoding as easy as 1-2...' by John</title>
<content type="html">&lt;p&gt;Something weird is going on&#8230; I can&#8217;t start the mongrel after installing the acts_as_geocodable plugin, it says that Graticules 0.2.0 is required and I have the 0.2.6 installed.. what am I doing wrong??&lt;/p&gt;</content>  </entry>
  <entry xml:base="http://opensoul.org/">
    <author>
      <name>Brandon</name>
    </author>
    <id>tag:opensoul.org,2007-02-13:1084:2504</id>
    <published>2007-03-15T03:08:33Z</published>
    <updated>2007-03-15T03:08:33Z</updated>
    <category term="Code"/>
    <link href="http://opensoul.org/2007/2/13/geocoding-as-easy-as-1-2" rel="alternate" type="text/html"/>
    <title>Comment on 'Geocoding as easy as 1-2...' by Brandon</title>
<content type="html">&lt;p&gt;Peter,&lt;/p&gt;


	&lt;p&gt;Sorry for the late response, I fell off the face of the earth for a week. You should be able to order the results by passing &lt;code&gt;:order =&amp;gt; 'distance'&lt;/code&gt; to the find. Let me know if that doesn&#8217;t work.&lt;/p&gt;</content>  </entry>
  <entry xml:base="http://opensoul.org/">
    <author>
      <name>PETER</name>
    </author>
    <id>tag:opensoul.org,2007-02-13:1084:2322</id>
    <published>2007-03-08T02:09:23Z</published>
    <updated>2007-03-08T02:09:23Z</updated>
    <category term="Code"/>
    <link href="http://opensoul.org/2007/2/13/geocoding-as-easy-as-1-2" rel="alternate" type="text/html"/>
    <title>Comment on 'Geocoding as easy as 1-2...' by PETER</title>
<content type="html">&lt;p&gt;Your approach of separating concerns is great.&lt;/p&gt;


	&lt;p&gt;It seems to me that being able to order results by distance as well as selecting by :within is important. Do you have plans to do this? Suggestions on how I might do it?&lt;/p&gt;


	&lt;p&gt;Thanks again&lt;/p&gt;</content>  </entry>
  <entry xml:base="http://opensoul.org/">
    <author>
      <name>James Stewart</name>
    </author>
    <id>tag:opensoul.org,2007-02-13:1084:1224</id>
    <published>2007-02-17T16:18:16Z</published>
    <updated>2007-02-17T16:18:16Z</updated>
    <category term="Code"/>
    <link href="http://opensoul.org/2007/2/13/geocoding-as-easy-as-1-2" rel="alternate" type="text/html"/>
    <title>Comment on 'Geocoding as easy as 1-2...' by James Stewart</title>
<content type="html">&lt;p&gt;Any thoughts of adding :through support for acts_as_geocodable? For example, say I have events which belong_to locations, it would be good to be able to search for forthcoming events based on their location.&lt;/p&gt;


	&lt;p&gt;I like the way acts_as_locateable implements that, but this plugin overall looks more appropriate for my needs.&lt;/p&gt;</content>  </entry>
  <entry xml:base="http://opensoul.org/">
    <author>
      <name>Shawn</name>
    </author>
    <id>tag:opensoul.org,2007-02-13:1084:1178</id>
    <published>2007-02-15T16:02:47Z</published>
    <updated>2007-02-15T16:02:47Z</updated>
    <category term="Code"/>
    <link href="http://opensoul.org/2007/2/13/geocoding-as-easy-as-1-2" rel="alternate" type="text/html"/>
    <title>Comment on 'Geocoding as easy as 1-2...' by Shawn</title>
<content type="html">&lt;p&gt;Hi Brandon,&lt;/p&gt;


	&lt;p&gt;Tested out the geocoder.nil? issue on Win XP.  It seems to only occur when the server is started in development mode.  Production mode, the object seems to stay created.&lt;/p&gt;


	&lt;p&gt;I tested using Mongrel and WEBrick with same results.&lt;/p&gt;


	&lt;p&gt;Hope this helps!&lt;/p&gt;


	&lt;p&gt;Shawn&lt;/p&gt;</content>  </entry>
  <entry xml:base="http://opensoul.org/">
    <author>
      <name>Shawn</name>
    </author>
    <id>tag:opensoul.org,2007-02-13:1084:1177</id>
    <published>2007-02-15T15:39:40Z</published>
    <updated>2007-02-15T15:39:40Z</updated>
    <category term="Code"/>
    <link href="http://opensoul.org/2007/2/13/geocoding-as-easy-as-1-2" rel="alternate" type="text/html"/>
    <title>Comment on 'Geocoding as easy as 1-2...' by Shawn</title>
<content type="html">&lt;p&gt;Hi Brandon,&lt;/p&gt;


	&lt;p&gt;Sure &#8211; I&#8217;m kinda, sorta new to &lt;span class=&quot;caps&quot;&gt;ROR&lt;/span&gt; but will try some things to see if cattr&#8217;s disappear on some other classes.&lt;/p&gt;


	&lt;p&gt;Here&#8217;s another item relating to Yahoo geocode requests&#8230;&lt;/p&gt;


	&lt;p&gt;In acts_as_geocoable.rb, the full_address method has a &#8221;\n&#8221; after the street.  This was causing Yahoo to return &lt;span class=&quot;caps&quot;&gt;ZIP&lt;/span&gt; level precision vs &lt;span class=&quot;caps&quot;&gt;STREET&lt;/span&gt; level.  Google didn&#8217;t seem to mind.&lt;/p&gt;


	&lt;p&gt;Orignal:&lt;/p&gt;


	&lt;p&gt;def full_address
          returning(&#8221;&#8221;) { |address|
            address &amp;lt;&amp;lt; &#8221;#{geo_attribute(:street)}\n&#8221; unless geo_attribute(:street).blank?
            address &amp;lt;&amp;lt; &#8221;#{geo_attribute(:city)}, &#8221; unless geo_attribute(:city).blank?
            address &amp;lt;&amp;lt; &#8221;#{geo_attribute(:region)} &#8221; unless geo_attribute(:region).blank?
            address &amp;lt;&amp;lt; &#8221;#{geo_attribute(:postal_code)}&#8221; unless geo_attribute(:postal_code).blank?
            address &amp;lt;&amp;lt; &#8221; #{geo_attribute(:country)}&#8221; unless geo_attribute(:country).blank?
          }.strip
        end&lt;/p&gt;


	&lt;p&gt;Changed to:&lt;/p&gt;


	&lt;ol&gt;
	&lt;li&gt;Return the entire address in one string.
def full_address
  returning(&#8221;&#8221;) { |address|
    address &amp;lt;&amp;lt; &#8221;#{geo_attribute(:street)},&#8221; unless geo_attribute(:street).blank?
    address &amp;lt;&amp;lt; &#8221;#{geo_attribute(:city)}, &#8221; unless geo_attribute(:city).blank?
    address &amp;lt;&amp;lt; &#8221;#{geo_attribute(:region)} &#8221; unless geo_attribute(:region).blank?
    address &amp;lt;&amp;lt; &#8221;#{geo_attribute(:postal_code)}&#8221; unless geo_attribute(:postal_code).blank?
    address &amp;lt;&amp;lt; &#8221; #{geo_attribute(:country)}&#8221; unless geo_attribute(:country).blank?
  }.strip
end&lt;/li&gt;
	&lt;/ol&gt;


	&lt;p&gt;Basically I replaced the &#8221;\n&#8221; with a &#8221;,&#8221;.  Yahoo now returns a &lt;span class=&quot;caps&quot;&gt;STREET&lt;/span&gt; level precision on valid address.  Google seems okay to.&lt;/p&gt;


	&lt;p&gt;Hope this helps!&lt;/p&gt;


	&lt;p&gt;Shawn&lt;/p&gt;</content>  </entry>
  <entry xml:base="http://opensoul.org/">
    <author>
      <name>Brandon</name>
    </author>
    <id>tag:opensoul.org,2007-02-13:1084:1144</id>
    <published>2007-02-14T16:17:16Z</published>
    <updated>2007-02-14T16:17:16Z</updated>
    <category term="Code"/>
    <link href="http://opensoul.org/2007/2/13/geocoding-as-easy-as-1-2" rel="alternate" type="text/html"/>
    <title>Comment on 'Geocoding as easy as 1-2...' by Brandon</title>
<content type="html">&lt;p&gt;Shawn,&lt;/p&gt;


	&lt;p&gt;That&#8217;s really odd. Looking through the code, I have no clue what would be causing that.&lt;/p&gt;


	&lt;p&gt;I don&#8217;t have immediate access to a Windows environment, so could you (or anyone else) help me debug it?&lt;/p&gt;</content>  </entry>
  <entry xml:base="http://opensoul.org/">
    <author>
      <name>Shawn</name>
    </author>
    <id>tag:opensoul.org,2007-02-13:1084:1115</id>
    <published>2007-02-14T00:47:10Z</published>
    <updated>2007-02-14T00:47:10Z</updated>
    <category term="Code"/>
    <link href="http://opensoul.org/2007/2/13/geocoding-as-easy-as-1-2" rel="alternate" type="text/html"/>
    <title>Comment on 'Geocoding as easy as 1-2...' by Shawn</title>
<content type="html">&lt;p&gt;Hi,&lt;/p&gt;


	&lt;p&gt;Thanks for the plugin! :)&lt;/p&gt;


	&lt;p&gt;I&#8217;ve installed Graticule and acts_as_geocodable but I can&#8217;t seem to get it to run reliably.&lt;/p&gt;


	&lt;p&gt;I&#8217;m on Windows XP, using a Yahoo Application id.&lt;/p&gt;


	&lt;p&gt;It seems setting Geocode.geocoder in the environment.rb isn&#8217;t &#8220;sticking&#8221;.  It set when the app is loaded but is nil when Geocode.rb is hit as part of the save process.&lt;/p&gt;


	&lt;p&gt;I&#8217;m working around this by using:&lt;/p&gt;


	&lt;pre&gt;&lt;code&gt;def self.geocode(location)&lt;/code&gt;&lt;/pre&gt;
	&lt;pre&gt;&lt;code&gt;if geocoder.nil?
    self.geocoder = Graticule.service(:yahoo).new 'Dd0Ib1zV34G4ypZoQ_DAedMH5uU7IejCvf5Mzw8llr2YkKFZzkymiyumE_OJ'
 end&lt;/code&gt;&lt;/pre&gt;


	&lt;pre&gt;&lt;code&gt;...&lt;/code&gt;&lt;/pre&gt;


	&lt;p&gt;end&lt;/p&gt;


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


	&lt;p&gt;Shawn&lt;/p&gt;</content>  </entry>
  <entry xml:base="http://opensoul.org/">
    <author>
      <name>jim</name>
    </author>
    <id>tag:opensoul.org,2007-02-13:1084:1105</id>
    <published>2007-02-13T15:37:00Z</published>
    <updated>2007-02-13T15:37:00Z</updated>
    <category term="Code"/>
    <link href="http://opensoul.org/2007/2/13/geocoding-as-easy-as-1-2" rel="alternate" type="text/html"/>
    <title>Comment on 'Geocoding as easy as 1-2...' by jim</title>
<content type="html">&lt;p&gt;Great work.  This is what I wanted to do but was short on time when I wrote acts_as_geocode. You guys did a much more thorough job.  I was just doing something quick to make my life easier on some real estate projects.&lt;/p&gt;


	&lt;p&gt;Now I will switch soon.&lt;/p&gt;</content>  </entry>
</feed>
