Provides geocoding based upon an IP address. The underlying web service is a which sources their data through a combination of publicly available information as well as community contributions.



A number of non-routable IP ranges.

— Sources for these:

  RFC 3330: Special-Use IPv4 Addresses
  The bogon list:

Private Class Methods

do_geocode(ip, options = {}) click to toggle source

Given an IP address, returns a GeoLoc instance which contains latitude, longitude, city, and country code. Sets the success attribute to false if the ip parameter does not match an ip address.

     # File /Users/andre/projects/rails/geokit/lib/geokit/geocoders.rb, line 588
588:       def self.do_geocode(ip, options = {})
589:         return unless /^(\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3})?$/.match(ip)
590:         return if self.private_ip_address?(ip)
591:         url = "{ip}&position=true"
592:         response = self.call_geocoder_service(url)
593:         response.is_a?(Net::HTTPSuccess) ? parse_body(response.body) :
594:       rescue
595:         logger.error "Caught an error during HostIp geocoding call: "+$!
596:         return
597:       end
private_ip_address?(ip) click to toggle source

Checks whether the IP address belongs to a private address range.

This function is used to reduce the number of useless queries made to the geocoding service. Such queries can occur frequently during integration tests.

     # File /Users/andre/projects/rails/geokit/lib/geokit/geocoders.rb, line 625
625:       def self.private_ip_address?(ip)
626:         return NON_ROUTABLE_IP_RANGES.any? { |range| range.include?(ip) }
627:       end

Disabled; run with --debug to generate this.


Generated with the Darkfish Rdoc Generator 1.1.6.