Skip to content

Commit

Permalink
added districts and provinces to google geocoder
Browse files Browse the repository at this point in the history
  • Loading branch information
Andre Lewis committed Sep 21, 2009
1 parent 24913cd commit 0fed9d9
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 5 deletions.
2 changes: 2 additions & 0 deletions lib/geokit/geocoders.rb
Expand Up @@ -486,10 +486,12 @@ def self.extract_placemark(doc)
#extended -- false if not not available
res.city = doc.elements['.//LocalityName'].text if doc.elements['.//LocalityName']
res.state = doc.elements['.//AdministrativeAreaName'].text if doc.elements['.//AdministrativeAreaName']
res.province = doc.elements['.//SubAdministrativeAreaName'].text if doc.elements['.//SubAdministrativeAreaName']
res.full_address = doc.elements['.//address'].text if doc.elements['.//address'] # google provides it
res.zip = doc.elements['.//PostalCodeNumber'].text if doc.elements['.//PostalCodeNumber']
res.street_address = doc.elements['.//ThoroughfareName'].text if doc.elements['.//ThoroughfareName']
res.country = doc.elements['.//CountryName'].text if doc.elements['.//CountryName']
res.district = doc.elements['.//DependentLocalityName'].text if doc.elements['.//DependentLocalityName']
# Translate accuracy into Yahoo-style token address, street, zip, zip+4, city, state, country
# For Google, 1=low accuracy, 8=high accuracy
address_details=doc.elements['.//*[local-name() = "AddressDetails"]']
Expand Down
9 changes: 5 additions & 4 deletions lib/geokit/mappable.rb
Expand Up @@ -342,7 +342,7 @@ class GeoLoc < LatLng

# Location attributes. Full address is a concatenation of all values. For example:
# 100 Spear St, San Francisco, CA, 94101, US
attr_accessor :street_address, :city, :state, :zip, :country_code, :country, :full_address, :all
attr_accessor :street_address, :city, :state, :zip, :country_code, :country, :full_address, :all, :district, :province
# Attributes set upon return from geocoding. Success will be true for successful
# geocode lookups. The provider will be set to the name of the providing geocoder.
# Finally, precision is an indicator of the accuracy of the geocoding.
Expand All @@ -361,7 +361,8 @@ def initialize(h={})
@city=h[:city]
@state=h[:state]
@zip=h[:zip]
@country_code=h[:country_code]
@country_code=h[:country_code]
@province = h[:province]
@success=false
@precision='unknown'
@full_address=nil
Expand Down Expand Up @@ -398,7 +399,7 @@ def street_name
# gives you all the important fields as key-value pairs
def hash
res={}
[:success,:lat,:lng,:country_code,:city,:state,:zip,:street_address,:provider,:full_address,:is_us?,:ll,:precision].each { |s| res[s] = self.send(s.to_s) }
[:success,:lat,:lng,:country_code,:city,:state,:zip,:street_address,:province,:district,:provider,:full_address,:is_us?,:ll,:precision].each { |s| res[s] = self.send(s.to_s) }
res
end
alias to_hash hash
Expand All @@ -416,7 +417,7 @@ def street_address=(address)
# Returns a comma-delimited string consisting of the street address, city, state,
# zip, and country code. Only includes those attributes that are non-blank.
def to_geocodeable_s
a=[street_address, city, state, zip, country_code].compact
a=[street_address, district, city, province, state, zip, country_code].compact
a.delete_if { |e| !e || e == '' }
a.join(', ')
end
Expand Down
2 changes: 1 addition & 1 deletion test/test_geoloc.rb
Expand Up @@ -65,7 +65,7 @@ def test_to_yaml
@loc.zip = '94105'
@loc.country_code = 'US'
assert_equal(
"--- !ruby/object:Geokit::GeoLoc \ncity: San Francisco\ncountry_code: US\nfull_address: \nlat: \nlng: \nprecision: unknown\nstate: CA\nstreet_address: \nsuccess: false\nzip: \"94105\"\n",
"--- !ruby/object:Geokit::GeoLoc \ncity: San Francisco\ncountry_code: US\nfull_address: \nlat: \nlng: \nprecision: unknown\nprovince: \nstate: CA\nstreet_address: \nsuccess: false\nzip: \"94105\"\n",
@loc.to_yaml)
end

Expand Down

0 comments on commit 0fed9d9

Please sign in to comment.