Skip to content

Commit

Permalink
Implement county for Google
Browse files Browse the repository at this point in the history
The documentation says:
> administrative_area_level_2: indicates a second-order civil entity below the country level. Within the United States, these administrative levels are counties.

Reference: https://developers.google.com/maps/documentation/geocoding/intro
  • Loading branch information
dsantosmerino committed Jan 22, 2020
1 parent 5a6ea0b commit 3690523
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 0 deletions.
1 change: 1 addition & 0 deletions lib/geokit/geocoders/google.rb
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,7 @@ def self.set_address_components(loc, addr)
loc.country = comp['long_name']
when types.include?('administrative_area_level_2')
loc.district = comp['long_name']
loc.county = comp['long_name']
when types.include?('neighborhood')
loc.neighborhood = comp['short_name']
# Use either sublocality or admin area level 3 if google does not return a city
Expand Down
5 changes: 5 additions & 0 deletions test/test_google_geocoder.rb
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,7 @@ def test_google_city
res = geocode(@address, :google_city)
assert_nil res.street_address
assert_equal 'CA', res.state
assert_equal 'San Francisco County', res.county
assert_equal 'San Francisco', res.city
assert_equal '37.7749295,-122.4194155', res.ll
assert res.is_us?
Expand All @@ -133,6 +134,7 @@ def test_google_sublocality
res = geocode(@address, :google_sublocality)
assert_equal '682 Prospect Place', res.street_address
assert_equal 'NY', res.state
assert_equal 'Kings County', res.county
assert_equal 'Brooklyn', res.city
assert_equal '40.6745812,-73.9541582', res.ll
assert res.is_us?
Expand All @@ -148,6 +150,7 @@ def test_google_administrative_area_level_3
res = geocode(@address, :google_administrative_area_level_3)
assert_equal '8 Barkwood Lane', res.street_address
assert_equal 'NY', res.state
assert_equal 'Saratoga County', res.county
assert_equal 'Clifton Park', res.city
assert_equal '42.829583,-73.788174', res.ll
assert res.is_us?
Expand Down Expand Up @@ -175,6 +178,7 @@ def test_google_city_with_geo_loc
TestHelper.expects(:last_url).with(url)
res = geocode(@google_city_loc, :google_city)
assert_equal 'CA', res.state
assert_equal 'San Francisco County', res.county
assert_equal 'San Francisco', res.city
assert_equal '37.7749295,-122.4194155', res.ll
assert res.is_us?
Expand Down Expand Up @@ -261,6 +265,7 @@ def test_reverse_geocode
assert_equal 'google', res.provider

assert_equal 'Madrid', res.city
assert_equal 'Madrid', res.county
assert_equal 'Community of Madrid', res.state

assert_equal 'Spain', res.country
Expand Down

0 comments on commit 3690523

Please sign in to comment.