Geocoder
Provides geocoding based upon an IP address. The underlying web service is geoplugin.net
(Not documented)
# File /Users/andre/projects/rails/geokit/lib/geokit/geocoders.rb, line 534
534: def self.do_geocode(ip, options = {})
535: return GeoLoc.new unless /^(\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3})?$/.match(ip)
536: response = self.call_geocoder_service("http://www.geoplugin.net/xml.gp?ip=#{ip}")
537: return response.is_a?(Net::HTTPSuccess) ? parse_xml(response.body) : GeoLoc.new
538: rescue
539: logger.error "Caught an error during GeoPluginGeocoder geocoding call: "+$!
540: return GeoLoc.new
541: end
(Not documented)
# File /Users/andre/projects/rails/geokit/lib/geokit/geocoders.rb, line 543
543: def self.parse_xml(xml)
544: xml = REXML::Document.new(xml)
545: geo = GeoLoc.new
546: geo.provider='geoPlugin'
547: geo.city = xml.elements['//geoplugin_city'].text
548: geo.state = xml.elements['//geoplugin_region'].text
549: geo.country_code = xml.elements['//geoplugin_countryCode'].text
550: geo.lat = xml.elements['//geoplugin_latitude'].text.to_f
551: geo.lng = xml.elements['//geoplugin_longitude'].text.to_f
552: geo.success = !!geo.city && !geo.city.empty?
553: return geo
554: end
Disabled; run with --debug to generate this.
Generated with the Darkfish Rdoc Generator 1.1.6.