I have installed the simplegeo-ruby gem and have been able to get this working through the Rails console, successfully creating records with the these commands:
(Note - I'm looking up the address via geokit and Google first)
>> @record = Record.new(:address => 'Address')
>> geocoded = Geokit::Geocoders::GoogleGeocoder.geocode @record.address
record = SimpleGeo::Record.new({
:id => @record.id,
:created => Time.now,
:lat => geocoded.lat,
:lon => geocoded.lng,
:layer => 'com.mylayer.records',
})
>> SimpleGeo::Client.add_record(record)
However my app is breaking when attempting to create a new record and throwing this error:
SimpleGeo::NotFound
app/controllers/records_controller.rb:24:in `create'
My RecordsController#create action looks like this:
def create
@record = Record.new(params[:record])
geocoded = Geokit::Geocoders::GoogleGeocoder.geocode @record.address
record = SimpleGeo::Record.new({
:id => @record.id,
:created => Time.now,
:lat => geocoded.lat,
:lon => geocoded.lng,
:layer => 'com.mylayer.records',
})
SimpleGeo::Client.add_record(record)
if @record.save
flash[:notice] = "Successfully created record."
redirect_to @record
else
render :action => 'new'
end
end
Any help or references using Simplegeo with Rails 3开发者_Python百科 are much appreciated.
Do you have the simplegeo gem in your Gemfile
? And have you ran bundle install
command? This is usually the problem when I've come across errors like this.
Is your layer called "com.mylayer.records"? That is usually just an example layer.
Create your own layers here: http://simplegeo.com/layers
If you cannot see that page, then you don't have access to the private beta of SimpleGeo Storage. It should be in the public in a few months though.
If you want to geocode addresses in the US, use SimpleGeo's /1.0/context endpoint: http://simplegeo.com/docs/api-endpoints/simplegeo-context#get-context
精彩评论