Class GeoKit::GeoLoc
In: vendor/plugins/geokit/lib/geo_kit/mappable.rb
Parent: LatLng

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.

Methods

Attributes

city  [RW]  Location attributes. Full address is a concatenation of all values. For example: 100 Spear St, San Francisco, CA, 94101, US
country_code  [RW]  Location attributes. Full address is a concatenation of all values. For example: 100 Spear St, San Francisco, CA, 94101, US
full_address  [RW]  Location attributes. Full address is a concatenation of all values. For example: 100 Spear St, San Francisco, CA, 94101, US
precision  [RW]  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.
provider  [RW]  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.
state  [RW]  Location attributes. Full address is a concatenation of all values. For example: 100 Spear St, San Francisco, CA, 94101, US
street_address  [RW]  Location attributes. Full address is a concatenation of all values. For example: 100 Spear St, San Francisco, CA, 94101, US
street_name  [R]  Street number and street name are extracted from the street address attribute.
street_number  [R]  Street number and street name are extracted from the street address attribute.
success  [RW]  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.
zip  [RW]  Location attributes. Full address is a concatenation of all values. For example: 100 Spear St, San Francisco, CA, 94101, US

Public Class methods

Constructor expects a hash of symbols to correspond with attributes.

[Source]

     # File vendor/plugins/geokit/lib/geo_kit/mappable.rb, line 283
283:     def initialize(h={})
284:       @street_address=h[:street_address] 
285:       @city=h[:city] 
286:       @state=h[:state] 
287:       @zip=h[:zip] 
288:       @country_code=h[:country_code] 
289:       @success=false
290:       @precision='unknown'
291:       super(h[:lat],h[:lng])
292:     end

Public Instance methods

Sets the city after capitalizing each word within the city name.

[Source]

     # File vendor/plugins/geokit/lib/geo_kit/mappable.rb, line 326
326:     def city=(city)
327:       @city = city.titleize if city
328:     end

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.

[Source]

     # File vendor/plugins/geokit/lib/geo_kit/mappable.rb, line 302
302:     def full_address
303:       @full_address ? @full_address : to_geocodeable_s
304:     end

gives you all the important fields as key-value pairs

[Source]

     # File vendor/plugins/geokit/lib/geo_kit/mappable.rb, line 318
318:     def hash
319:       res={}
320:       [: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) }
321:       res
322:     end

Returns true if geocoded to the United States.

[Source]

     # File vendor/plugins/geokit/lib/geo_kit/mappable.rb, line 295
295:     def is_us?
296:       country_code == 'US'
297:     end

Sets the street address after capitalizing each word within the street address.

[Source]

     # File vendor/plugins/geokit/lib/geo_kit/mappable.rb, line 331
331:     def street_address=(address)
332:       @street_address = address.titleize if address
333:     end

Returns the street name portion of the street address.

[Source]

     # File vendor/plugins/geokit/lib/geo_kit/mappable.rb, line 313
313:     def street_name
314:        street_address[street_number.length, street_address.length].strip if street_address
315:     end

Extracts the street number from the street address if the street address has a value.

[Source]

     # File vendor/plugins/geokit/lib/geo_kit/mappable.rb, line 308
308:     def street_number
309:       street_address[/(\d*)/] if street_address
310:     end

Returns a comma-delimited string consisting of the street address, city, state, zip, and country code. Only includes those attributes that are non-blank.

[Source]

     # File vendor/plugins/geokit/lib/geo_kit/mappable.rb, line 337
337:     def to_geocodeable_s
338:       a=[street_address, city, state, zip, country_code].compact
339:       a.delete_if { |e| !e || e == '' }
340:       a.join(', ')      
341:     end
to_hash()

Alias for hash

Returns a string representation of the instance.

[Source]

     # File vendor/plugins/geokit/lib/geo_kit/mappable.rb, line 344
344:     def to_s
345:       "Provider: #{provider}\n Street: #{street_address}\nCity: #{city}\nState: #{state}\nZip: #{zip}\nLatitude: #{lat}\nLongitude: #{lng}\nCountry: #{country_code}\nSuccess: #{success}"
346:     end

[Validate]