Class: GeoKit::GeoLoc
Overview
This class encapsulates the result of a geocoding call It’s primary purpose is to homogenize the results of multiple geocoding providers. It also provides some additional functionality, such as the “full address” method for geocoders that do not provide a full address in their results (for example, Yahoo), and the “is_us” method.
Constant Summary
Constants included from Mappable
Mappable::EARTH_RADIUS_IN_KMS, Mappable::EARTH_RADIUS_IN_MILES, Mappable::KMS_PER_LATITUDE_DEGREE, Mappable::KMS_PER_MILE, Mappable::LATITUDE_DEGREES, Mappable::MILES_PER_LATITUDE_DEGREE, Mappable::PI_DIV_RAD
Instance Attribute Summary collapse
-
#city ⇒ Object
Location attributes.
-
#country_code ⇒ Object
Location attributes.
-
#full_address ⇒ Object
full_address is provided by google but not by yahoo.
-
#precision ⇒ Object
Attributes set upon return from geocoding.
-
#provider ⇒ Object
Attributes set upon return from geocoding.
-
#state ⇒ Object
Location attributes.
-
#street_address ⇒ Object
Location attributes.
-
#street_name ⇒ Object
readonly
Returns the street name portion of the street address.
-
#street_number ⇒ Object
readonly
Extracts the street number from the street address if the street address has a value.
-
#success ⇒ Object
Attributes set upon return from geocoding.
-
#zip ⇒ Object
Location attributes.
Attributes inherited from LatLng
Instance Method Summary collapse
-
#hash ⇒ Object
(also: #to_hash)
gives you all the important fields as key-value pairs.
-
#initialize(h = {}) ⇒ GeoLoc
constructor
Constructor expects a hash of symbols to correspond with attributes.
-
#is_us? ⇒ Boolean
Returns true if geocoded to the United States.
-
#to_geocodeable_s ⇒ Object
Returns a comma-delimited string consisting of the street address, city, state, zip, and country code.
-
#to_s ⇒ Object
Returns a string representation of the instance.
Methods inherited from LatLng
Methods included from Mappable
#distance_to, #endpoint, #heading_from, #heading_to, included, #midpoint_to, #to_lat_lng
Constructor Details
#initialize(h = {}) ⇒ GeoLoc
Constructor expects a hash of symbols to correspond with attributes.
283 284 285 286 287 288 289 290 291 292 |
# File 'lib/geo_kit/mappable.rb', line 283 def initialize(h={}) @street_address=h[:street_address] @city=h[:city] @state=h[:state] @zip=h[:zip] @country_code=h[:country_code] @success=false @precision='unknown' super(h[:lat],h[:lng]) end |
Instance Attribute Details
#city ⇒ Object
Location attributes. Full address is a concatenation of all values. For example: 100 Spear St, San Francisco, CA, 94101, US
274 275 276 |
# File 'lib/geo_kit/mappable.rb', line 274 def city @city end |
#country_code ⇒ Object
Location attributes. Full address is a concatenation of all values. For example: 100 Spear St, San Francisco, CA, 94101, US
274 275 276 |
# File 'lib/geo_kit/mappable.rb', line 274 def country_code @country_code end |
#full_address ⇒ Object
full_address is provided by google but not by yahoo. It is intended that the google geocoding method will provide the full address, whereas for yahoo it will be derived from the parts of the address we do have.
274 275 276 |
# File 'lib/geo_kit/mappable.rb', line 274 def full_address @full_address end |
#precision ⇒ Object
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.
278 279 280 |
# File 'lib/geo_kit/mappable.rb', line 278 def precision @precision end |
#provider ⇒ Object
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.
278 279 280 |
# File 'lib/geo_kit/mappable.rb', line 278 def provider @provider end |
#state ⇒ Object
Location attributes. Full address is a concatenation of all values. For example: 100 Spear St, San Francisco, CA, 94101, US
274 275 276 |
# File 'lib/geo_kit/mappable.rb', line 274 def state @state end |
#street_address ⇒ Object
Location attributes. Full address is a concatenation of all values. For example: 100 Spear St, San Francisco, CA, 94101, US
274 275 276 |
# File 'lib/geo_kit/mappable.rb', line 274 def street_address @street_address end |
#street_name ⇒ Object (readonly)
Returns the street name portion of the street address.
280 281 282 |
# File 'lib/geo_kit/mappable.rb', line 280 def street_name @street_name end |
#street_number ⇒ Object (readonly)
Extracts the street number from the street address if the street address has a value.
280 281 282 |
# File 'lib/geo_kit/mappable.rb', line 280 def street_number @street_number end |
#success ⇒ Object
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.
278 279 280 |
# File 'lib/geo_kit/mappable.rb', line 278 def success @success end |
#zip ⇒ Object
Location attributes. Full address is a concatenation of all values. For example: 100 Spear St, San Francisco, CA, 94101, US
274 275 276 |
# File 'lib/geo_kit/mappable.rb', line 274 def zip @zip end |
Instance Method Details
#hash ⇒ Object Also known as: to_hash
gives you all the important fields as key-value pairs
318 319 320 321 322 |
# File 'lib/geo_kit/mappable.rb', line 318 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) } res end |
#is_us? ⇒ Boolean
Returns true if geocoded to the United States.
295 296 297 |
# File 'lib/geo_kit/mappable.rb', line 295 def is_us? country_code == 'US' end |
#to_geocodeable_s ⇒ Object
Returns a comma-delimited string consisting of the street address, city, state, zip, and country code. Only includes those attributes that are non-blank.
337 338 339 340 341 |
# File 'lib/geo_kit/mappable.rb', line 337 def to_geocodeable_s a=[street_address, city, state, zip, country_code].compact a.delete_if { |e| !e || e == '' } a.join(', ') end |
#to_s ⇒ Object
Returns a string representation of the instance.
344 345 346 |
# File 'lib/geo_kit/mappable.rb', line 344 def to_s "Provider: #{provider}\n Street: #{street_address}\nCity: #{city}\nState: #{state}\nZip: #{zip}\nLatitude: #{lat}\nLongitude: #{lng}\nCountry: #{country_code}\nSuccess: #{success}" end |