Parent

Geokit::GeoLoc

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.

Some geocoders can return multple results. Geoloc can capture multiple results through its “all” method.

For the geocoder setting the results, it would look something like this:

    geo=GeoLoc.new(first_result)
    geo.all.push(second_result)
    geo.all.push(third_result)

Then, for the user of the result:

    puts geo.full_address     # just like usual
    puts geo.all.size  => 3   # there's three results total
    puts geo.all.first        # all is just an array or additional geolocs,
                                so do what you want with it

Attributes

street_address[RW]

Location attributes. Full address is a concatenation of all values. For example: 100 Spear St, San Francisco, CA, 94101, US

city[RW]

Location attributes. Full address is a concatenation of all values. For example: 100 Spear St, San Francisco, CA, 94101, US

state[RW]

Location attributes. Full address is a concatenation of all values. For example: 100 Spear St, San Francisco, CA, 94101, US

zip[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

country[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

all[RW]

Location attributes. Full address is a concatenation of all values. For example: 100 Spear St, San Francisco, CA, 94101, US

district[RW]

Location attributes. Full address is a concatenation of all values. For example: 100 Spear St, San Francisco, CA, 94101, US

province[RW]

Location attributes. Full address is a concatenation of all values. For example: 100 Spear St, San Francisco, CA, 94101, US

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.

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.

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.

suggested_bounds[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.

street_number[R]

Street number and street name are extracted from the street address attribute.

street_name[R]

Street number and street name are extracted from the street address attribute.

accuracy[RW]

accuracy is set for Yahoo and Google geocoders, it is a numeric value of the precision. see code.google.com/apis/maps/documentation/geocoding/#GeocodingAccuracy

Public Class Methods

new(h={}) click to toggle source

Constructor expects a hash of symbols to correspond with attributes.

     # File /Users/andre/projects/rails/geokit/lib/geokit/mappable.rb, line 357
357:     def initialize(h={})
358:       @all = [self]
359:       
360:       @street_address=h[:street_address] 
361:       @city=h[:city] 
362:       @state=h[:state] 
363:       @zip=h[:zip] 
364:       @country_code=h[:country_code]
365:       @province = h[:province]
366:       @success=false
367:       @precision='unknown'
368:       @full_address=nil
369:       super(h[:lat],h[:lng])
370:     end

Public Instance Methods

city=(city) click to toggle source

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

     # File /Users/andre/projects/rails/geokit/lib/geokit/mappable.rb, line 408
408:     def city=(city)
409:       @city = Geokit::Inflector::titleize(city) if city
410:     end
full_address() click to toggle source

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.

     # File /Users/andre/projects/rails/geokit/lib/geokit/mappable.rb, line 384
384:     def full_address
385:       @full_address ? @full_address : to_geocodeable_s
386:     end
hash() click to toggle source

gives you all the important fields as key-value pairs

     # File /Users/andre/projects/rails/geokit/lib/geokit/mappable.rb, line 400
400:     def hash
401:       res={}
402:       [: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) }
403:       res
404:     end
Also aliased as: to_hash
is_us?() click to toggle source

Returns true if geocoded to the United States.

     # File /Users/andre/projects/rails/geokit/lib/geokit/mappable.rb, line 373
373:     def is_us?
374:       country_code == 'US'
375:     end
street_address=(address) click to toggle source

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

     # File /Users/andre/projects/rails/geokit/lib/geokit/mappable.rb, line 413
413:     def street_address=(address)
414:       @street_address = Geokit::Inflector::titleize(address) if address
415:     end
street_name() click to toggle source

Returns the street name portion of the street address.

     # File /Users/andre/projects/rails/geokit/lib/geokit/mappable.rb, line 395
395:     def street_name
396:        street_address[street_number.length, street_address.length].strip if street_address
397:     end
street_number() click to toggle source

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

     # File /Users/andre/projects/rails/geokit/lib/geokit/mappable.rb, line 390
390:     def street_number
391:       street_address[/(\d*)/] if street_address
392:     end
success?() click to toggle source

(Not documented)

     # File /Users/andre/projects/rails/geokit/lib/geokit/mappable.rb, line 377
377:     def success?
378:       success == true
379:     end
to_geocodeable_s() click to toggle source

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

     # File /Users/andre/projects/rails/geokit/lib/geokit/mappable.rb, line 419
419:     def to_geocodeable_s
420:       a=[street_address, district, city, province, state, zip, country_code].compact
421:       a.delete_if { |e| !e || e == '' }
422:       a.join(', ')      
423:     end
to_hash() click to toggle source

Alias for hash

to_s() click to toggle source

Returns a string representation of the instance.

     # File /Users/andre/projects/rails/geokit/lib/geokit/mappable.rb, line 430
430:     def to_s
431:       "Provider: #{provider}\nStreet: #{street_address}\nCity: #{city}\nState: #{state}\nZip: #{zip}\nLatitude: #{lat}\nLongitude: #{lng}\nCountry: #{country_code}\nSuccess: #{success}"
432:     end
to_yaml_properties() click to toggle source

(Not documented)

     # File /Users/andre/projects/rails/geokit/lib/geokit/mappable.rb, line 425
425:     def to_yaml_properties
426:       (instance_variables - ['@all']).sort
427:     end

Disabled; run with --debug to generate this.

[Validate]

Generated with the Darkfish Rdoc Generator 1.1.6.