Sha256: a6ab2ae372f01971aab0b806c21f5ea53f9d2a1a1995b17c8816bd5e594d8642
Contents?: true
Size: 1.61 KB
Versions: 1
Compression:
Stored size: 1.61 KB
Contents
module Geokit module Geocoders class FCCGeocoder < Geocoder self.secure = true private # Template method which does the reverse-geocode lookup. def self.do_reverse_geocode(latlng) latlng = LatLng.normalize(latlng) url = "#{protocol}://data.fcc.gov/api/block/find?format=json&latitude=#{Geokit::Inflector.url_escape(latlng.lat.to_s)}&longitude=#{Geokit::Inflector.url_escape(latlng.lng.to_s)}" process :json, url end # Template method which does the geocode lookup. # # ==== EXAMPLES # ll=Geokit::LatLng.new(40, -85) # Geokit::Geocoders::FCCGeocoder.geocode(ll) # # JSON result looks like this # => {"County"=>{"name"=>"Wayne", "FIPS"=>"18177"}, # "Block"=>{"FIPS"=>"181770103002004"}, # "executionTime"=>"0.099", # "State"=>{"name"=>"Indiana", "code"=>"IN", "FIPS"=>"18"}, # "status"=>"OK"} def self.parse_json(results) if results.key?("Err") && results["Err"]["msg"] == "There are no results for this location" return GeoLoc.new end # this should probably be smarter. raise Geokit::Geocoders::GeocodeError if !results["status"] == "OK" loc = new_loc loc.success = true loc.precision = "block" loc.country_code = "US" loc.district = results["County"]["name"] loc.district_fips = results["County"]["FIPS"] loc.state = results["State"]["code"] loc.state_fips = results["State"]["FIPS"] loc.block_fips = results["Block"]["FIPS"] loc end end end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
geokit-1.10.0 | lib/geokit/geocoders/fcc.rb |