lib/geokit/geocoders/yandex.rb in geokit-1.10.0 vs lib/geokit/geocoders/yandex.rb in geokit-1.11.0
- old
+ new
@@ -6,11 +6,11 @@
config :key
private
# Template method which does the geocode lookup.
- def self.do_geocode(address)
+ def self.do_geocode(address, _=nil)
process :json, submit_url(address)
end
def self.submit_url(address)
address_str = address.is_a?(GeoLoc) ? address.to_geocodeable_s : address
@@ -20,41 +20,42 @@
end
def self.parse_json(result)
loc = new_loc
- coll = result["response"]["GeoObjectCollection"]
- return loc unless coll["metaDataProperty"]["GeocoderResponseMetaData"]["found"].to_i > 0
+ coll = result['response']['GeoObjectCollection']
+ return loc unless coll['metaDataProperty']['GeocoderResponseMetaData']['found'].to_i > 0
- l = coll["featureMember"][0]["GeoObject"]
+ l = coll['featureMember'][0]['GeoObject']
loc.success = true
- ll = l["Point"]["pos"].split(" ")
+ ll = l['Point']['pos'].split(' ')
loc.lng = ll.first
loc.lat = ll.last
- country = l["metaDataProperty"]["GeocoderMetaData"]["AddressDetails"]["Country"]
- locality = country["Locality"] || country["AdministrativeArea"]["Locality"] || country["AdministrativeArea"]["SubAdministrativeArea"]["Locality"] rescue nil
+ country = l['metaDataProperty']['GeocoderMetaData']['AddressDetails']['Country']
+ locality = country['Locality'] || country['AdministrativeArea']['Locality'] || country['AdministrativeArea']['SubAdministrativeArea']['Locality'] rescue nil
set_address_components(loc, l, country, locality)
set_precision(loc, l, locality)
loc
end
def self.set_address_components(loc, l, country, locality)
- loc.country_code = country["CountryNameCode"]
- loc.full_address = country["AddressLine"]
- loc.street_address = l["name"]
- loc.street_number = locality["Thoroughfare"]["Premise"]["PremiseNumber"] rescue nil
- loc.street_name = locality["Thoroughfare"]["ThoroughfareName"] rescue nil
- loc.city = locality["LocalityName"] rescue nil
- loc.state_name = country["AdministrativeArea"]["AdministrativeAreaName"] rescue nil
- loc.state ||= country["Locality"]["LocalityName"] rescue nil
+ loc.country_code = country['CountryNameCode']
+ loc.full_address = country['AddressLine']
+ loc.street_address = l['name']
+ loc.street_number = locality['Thoroughfare']['Premise']['PremiseNumber'] rescue nil
+ loc.street_name = locality['Thoroughfare']['ThoroughfareName'] rescue nil
+ loc.city = locality['LocalityName'] rescue nil
+ loc.state_name = country['AdministrativeArea']['AdministrativeAreaName'] rescue nil
+ loc.district = country['AdministrativeArea']['SubAdministrativeArea']['SubAdministrativeAreaName'] rescue nil
+ loc.state ||= country['Locality']['LocalityName'] rescue nil
end
def self.set_precision(loc, l, locality)
- loc.precision = l["metaDataProperty"]["GeocoderMetaData"]["precision"].sub(/exact/, "building").sub(/number|near/, "address").sub(/other/, "city")
- loc.precision = "country" unless locality
+ loc.precision = l['metaDataProperty']['GeocoderMetaData']['precision'].sub(/exact/, 'building').sub(/number|near/, 'address').sub(/other/, 'city')
+ loc.precision = 'country' unless locality
end
end
end
end