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.
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
Location attributes. Full address is a concatenation of all values. For example: 100 Spear St, San Francisco, CA, 94101, US
Location attributes. Full address is a concatenation of all values. For example: 100 Spear St, San Francisco, CA, 94101, US
Location attributes. Full address is a concatenation of all values. For example: 100 Spear St, San Francisco, CA, 94101, US
Location attributes. Full address is a concatenation of all values. For example: 100 Spear St, San Francisco, CA, 94101, US
Location attributes. Full address is a concatenation of all values. For example: 100 Spear St, San Francisco, CA, 94101, US
Location attributes. Full address is a concatenation of all values. For example: 100 Spear St, San Francisco, CA, 94101, US
Location attributes. Full address is a concatenation of all values. For example: 100 Spear St, San Francisco, CA, 94101, US
Location attributes. Full address is a concatenation of all values. For example: 100 Spear St, San Francisco, CA, 94101, US
Location attributes. Full address is a concatenation of all values. For example: 100 Spear St, San Francisco, CA, 94101, US
Location attributes. Full address is a concatenation of all values. For example: 100 Spear St, San Francisco, CA, 94101, US
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.
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.
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.
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.
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
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
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 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
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
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
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
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
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
(Not documented)
# File /Users/andre/projects/rails/geokit/lib/geokit/mappable.rb, line 377
377: def success?
378: success == true
379: 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.
# 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
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
Disabled; run with --debug to generate this.
Generated with the Darkfish Rdoc Generator 1.1.6.