Sha256: e2c13a9501687c9d4b652f44b72b3b5b3a38ead695d4c3ab0900fd2e718f0977

Contents?: true

Size: 721 Bytes

Versions: 5

Compression:

Stored size: 721 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)
        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.kind_of?(Numeric) && res.latitude.kind_of?(Numeric) )
        loc
      end
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
geokit-1.9.0 lib/geokit/geocoders/maxmind.rb
geokit-1.8.5 lib/geokit/geocoders/maxmind.rb
geokit-1.8.4 lib/geokit/geocoders/maxmind.rb
geokit-1.8.3 lib/geokit/geocoders/maxmind.rb
geokit-1.8.2 lib/geokit/geocoders/maxmind.rb