开发者

Using Rails 3 with Geokit-rails3 location gem

开发者 https://www.devze.com 2023-02-15 13:53 出处:网络
I am trying to use the geokit-rails3 gem for geolocation information in a rails application. I have a simple model:

I am trying to use the geokit-rails3 gem for geolocation information in a rails application. I have a simple model:

class Location < ActiveRecord::Base
  def lookup_ip_information(post_ip)
    ip = post_ip
    location = IpGeocoder.geocode(ip)
    puts location.full_address
    lat = location.lat
    lng = location.lng
  end
end

When I call this method with request.remote_ip from my controller, it's throwing an error: uninitialized开发者_如何学JAVA constant Location::IpGeocoder


I just had this issue and resolved it by entering the full

Geokit::Geocoders::IpGeocoder.geocode(request.remote_ip)

and that seemed to solve it for me.


Had the same issue and couldn't get IpGeocoder to work in Rails3 with above suggestions. Dug into the Rails3 source code for the gem. Looks like an easy way to work around this is use the Geokit MultiGeocoder method for Rails 3.

Example: loc = Geokit::Geocoders::MultiGeocoder.geocode(remote.request_ip)

Don't forget to set up MultiGeocoder correctly in your initializer - geokit_config.rb Geokit::Geocoders::provider_order = [:google,:us]

0

精彩评论

暂无评论...
验证码 换一张
取 消