Class: Yahoo::Geocode
- Inherits:
-
Yahoo
- Object
- Yahoo
- Yahoo::Geocode
- Defined in:
- lib/yahoo/geocode.rb
Overview
Yahoo geocoding API.
Defined Under Namespace
Classes: Location
Constant Summary collapse
- VERSION =
'1.1.1'
Instance Method Summary collapse
-
#initialize(*args) ⇒ Geocode
constructor
:nodoc:.
-
#locate(address) ⇒ Object
Returns a Location for
address
. -
#parse_response(xml) ⇒ Object
:nodoc:.
Constructor Details
#initialize(*args) ⇒ Geocode
:nodoc:
19 20 21 22 23 24 |
# File 'lib/yahoo/geocode.rb', line 19 def initialize(*args) # :nodoc: @host = 'api.local.yahoo.com' @service_name = 'MapsService' @version = 'V1' super end |
Instance Method Details
#locate(address) ⇒ Object
Returns a Location for address
.
The address
can be any of:
-
city, state
-
city, state, zip
-
zip
-
street, city, state
-
street, city, state, zip
-
street, zip
37 38 39 |
# File 'lib/yahoo/geocode.rb', line 37 def locate(address) get :geocode, :location => address end |
#parse_response(xml) ⇒ Object
:nodoc:
41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 |
# File 'lib/yahoo/geocode.rb', line 41 def parse_response(xml) # :nodoc: addresses = [] xml.elements['ResultSet'].each do |r| address = Location.new address.precision = r.attributes['precision'] if r.attributes.include? 'warning' then address.warning = r.attributes['warning'] end address.latitude = r.elements['Latitude'].text.to_f address.longitude = r.elements['Longitude'].text.to_f address.address = r.elements['Address'].text address.city = r.elements['City'].text address.state = r.elements['State'].text address.zip = r.elements['Zip'].text address.country = r.elements['Country'].text addresses << address end return addresses end |