class Geokit::Geocoders::FCCGeocoder

Private Class Methods

do_reverse_geocode(latlng) click to toggle source

Template method which does the reverse-geocode lookup.

# File lib/geokit/geocoders/fcc.rb, line 9
def self.do_reverse_geocode(latlng)
  latlng = LatLng.normalize(latlng)
  url = "#{protocol}://geo.fcc.gov/api/census/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
parse_json(results) click to toggle source

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”}

# File lib/geokit/geocoders/fcc.rb, line 28
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