Skip to content

Instantly share code, notes, and snippets.

@neotericdesign
Created November 3, 2010 17:16
Show Gist options
  • Select an option

  • Save neotericdesign/661381 to your computer and use it in GitHub Desktop.

Select an option

Save neotericdesign/661381 to your computer and use it in GitHub Desktop.
> e = Event.first
=> #<Event id: 3, title: "GULAG Art", start_at: "2010-10-01 09:00:00", end_at: "2010-12-31 23:59:00", registration_link: "", description: "<p><strong>Through December 2010</strong>\r\n</p>\r\n<p...", thumbnail_id: 16, venue_name: "The Joseph Regenstein Library", venue_address: "1100 East 57th Street, 2nd Floor Reading Room Chica...", venue_url: "http://lib.uchicago.edu", venue_phone: "", is_featured: false, presenter_id: 28, position: 2, created_at: "2010-10-20 21:20:58", updated_at: "2010-11-03 17:06:14", lat: #<BigDecimal:1051e6dc8,'0.9999999999E0',18(27)>, lng: #<BigDecimal:1051e6d00,'-0.9999999999E0',18(27)>>
ruby-1.8.7-p302 > include Geokit::Geocoders
=> Object
ruby-1.8.7-p302 > res=MultiGeocoder.geocode(e.venue_address)
=> #<Geokit::GeoLoc:0x10510dac8 @lng=-87.6297982, @full_address="Chicago, IL, USA", @suggested_bounds=#<Geokit::Bounds:0x1050588f8 @sw=#<Geokit::LatLng:0x105058830 @lng=-87.885917, @lat=41.7450495>, @ne=#<Geokit::LatLng:0x105058768 @lng=-87.3736794, @lat=42.0109012>>, @country_code="US", @state="IL", @all=[#<Geokit::GeoLoc:0x10510dac8 ...>], @accuracy=4, @lat=41.8781136, @precision="city", @provider="google", @zip=nil, @success=true, @city="Chicago", @province="Cook", @country="USA", @street_address=nil>
ruby-1.8.7-p302 >
ruby-1.8.7-p302 >
ruby-1.8.7-p302 > res.ll.split(',')[0]
=> "41.8781136"
ruby-1.8.7-p302 > res.ll
=> "41.8781136,-87.6297982"
ruby-1.8.7-p302 > res.ll.split(',')[1]
=> "-87.6297982"
ruby-1.8.7-p302 > res.ll.split(',')[1].to_f
=> -87.6297982
Completed 200 OK in 107ms (Views: 99.3ms | ActiveRecord: 6.9ms)
>>>>>>>>>>>>>>>>>>>>>>>>>>>> 41.8781136 -87.6297982
class Event < ActiveRecord::Base
include Geokit::Geocoders
before_save :get_lat_and_lng
# ...
private
def get_lat_and_lng
res=MultiGeocoder.geocode(self.venue_address)
self.lat = res.ll.split(',')[0].to_f
self.lng = res.ll.split(',')[1].to_f
puts ">>>>>>>>>>>>>>>>>>>>>>>>>>>> #{lat} #{lng}"
end
lat: 0.9999999999
lng: -0.9999999999
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment