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

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

all[RW]

Location attributes. Full address is a concatenation of all values. For example: 100 Spear St, San Francisco, CA, 94101, US Street number and street name are extracted from the street address attribute if they don't exist

block_fips[RW]

FCC Attributes

city[RW]

Location attributes. Full address is a concatenation of all values. For example: 100 Spear St, San Francisco, CA, 94101, US Street number and street name are extracted from the street address attribute if they don't exist

country[RW]

Location attributes. Full address is a concatenation of all values. For example: 100 Spear St, San Francisco, CA, 94101, US Street number and street name are extracted from the street address attribute if they don't exist

country_code[RW]

Location attributes. Full address is a concatenation of all values. For example: 100 Spear St, San Francisco, CA, 94101, US Street number and street name are extracted from the street address attribute if they don't exist

district[RW]

Location attributes. Full address is a concatenation of all values. For example: 100 Spear St, San Francisco, CA, 94101, US Street number and street name are extracted from the street address attribute if they don't exist

district_fips[RW]

FCC Attributes

full_address[RW]

Location attributes. Full address is a concatenation of all values. For example: 100 Spear St, San Francisco, CA, 94101, US Street number and street name are extracted from the street address attribute if they don't exist

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.

province[RW]

Location attributes. Full address is a concatenation of all values. For example: 100 Spear St, San Francisco, CA, 94101, US Street number and street name are extracted from the street address attribute if they don't exist

state[RW]

Location attributes. Full address is a concatenation of all values. For example: 100 Spear St, San Francisco, CA, 94101, US Street number and street name are extracted from the street address attribute if they don't exist

state_fips[RW]

FCC Attributes

street_address[RW]

Location attributes. Full address is a concatenation of all values. For example: 100 Spear St, San Francisco, CA, 94101, US Street number and street name are extracted from the street address attribute if they don't exist

street_name[RW]

Location attributes. Full address is a concatenation of all values. For example: 100 Spear St, San Francisco, CA, 94101, US Street number and street name are extracted from the street address attribute if they don't exist

street_number[RW]

Location attributes. Full address is a concatenation of all values. For example: 100 Spear St, San Francisco, CA, 94101, US Street number and street name are extracted from the street address attribute if they don't exist

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.

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.

zip[RW]

Location attributes. Full address is a concatenation of all values. For example: 100 Spear St, San Francisco, CA, 94101, US Street number and street name are extracted from the street address attribute if they don't exist

Public Class Methods

new(h={}) click to toggle source

Constructor expects a hash of symbols to correspond with attributes.

# File lib/geokit/mappable.rb, line 361
def initialize(h={})
  @all = [self]
  
  @street_address=h[:street_address] 
  @street_number=nil
  @street_name=nil
  @city=h[:city] 
  @state=h[:state] 
  @zip=h[:zip] 
  @country_code=h[:country_code]
  @province = h[:province]
  @success=false
  @precision='unknown'
  @full_address=nil
  super(h[:lat],h[:lng])
end

Public Instance Methods

city=(city) click to toggle source

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

# File lib/geokit/mappable.rb, line 415
def city=(city)
  @city = Geokit::Inflector::titleize(city) if city
end
hash() click to toggle source

gives you all the important fields as key-value pairs

# File lib/geokit/mappable.rb, line 407
def hash
  res={}
  [:success,:lat,:lng,:country_code,:city,:state,:zip,:street_address,:province,:district,:provider,:full_address,:is_us?,:ll,:precision,:district_fips,:state_fips,:block_fips].each { |s| res[s] = self.send(s.to_s) }
  res
end
Also aliased as: to_hash
is_us?() click to toggle source

Returns true if geocoded to the United States.

# File lib/geokit/mappable.rb, line 379
def is_us?
  country_code == 'US'
end
street_address=(address) click to toggle source

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

# File lib/geokit/mappable.rb, line 420
def street_address=(address)
  if address and not ['google','google3'].include?(self.provider)
    @street_address = Geokit::Inflector::titleize(address) 
  else
    @street_address = address
  end
end
success?() click to toggle source
# File lib/geokit/mappable.rb, line 383
def success?
  success == true
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 lib/geokit/mappable.rb, line 430
def to_geocodeable_s
  a=[street_address, district, city, province, state, zip, country_code].compact
  a.delete_if { |e| !e || e == '' }
  a.join(', ')      
end
to_hash() click to toggle source
Alias for: hash
to_s() click to toggle source

Returns a string representation of the instance.

# File lib/geokit/mappable.rb, line 441
def to_s
  "Provider: #{provider}\nStreet: #{street_address}\nCity: #{city}\nState: #{state}\nZip: #{zip}\nLatitude: #{lat}\nLongitude: #{lng}\nCountry: #{country_code}\nSuccess: #{success}"
end
to_yaml_properties() click to toggle source
# File lib/geokit/mappable.rb, line 436
def to_yaml_properties
  (instance_variables - ['@all']).sort
end

[Validate]

Generated with the Darkfish Rdoc Generator 2.