Sha256: a3b2204ae98b76b3012648691d11011517ec9172ba7da58be8bb85afedc114e2

Contents?: true

Size: 720 Bytes

Versions: 5

Compression:

Stored size: 720 Bytes

Contents

module Geokit
  module Geocoders
    # Provides geocoding based upon an IP address.  The underlying web service is MaxMind
    class MaxmindGeocoder < Geocoder
      config :geoip_data_path # path to GeoLiteCity.dat

      private

      def self.do_geocode(ip, _=nil)
        res = GeoIP.new(geoip_data_path).city(ip)

        loc = new_loc
        loc.lat          = res.latitude
        loc.lng          = res.longitude
        loc.city         = res.city_name
        loc.state        = res.region_name
        loc.zip          = res.postal_code
        loc.country_code = res.country_code2

        loc.success = (res.longitude.is_a?(Numeric) && res.latitude.is_a?(Numeric))
        loc
      end
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
geokit-1.14.0 lib/geokit/geocoders/maxmind.rb
geokit-1.13.1 lib/geokit/geocoders/maxmind.rb
geokit-1.13.0 lib/geokit/geocoders/maxmind.rb
geokit-1.12.0 lib/geokit/geocoders/maxmind.rb
geokit-1.11.0 lib/geokit/geocoders/maxmind.rb