Class: GoogleMaps::Geocoder::Location

Inherits:
Object
  • Object
show all
Defined in:
lib/google_maps/geocoder/location.rb

Constant Summary collapse

LOCATION_TYPES =
[ "ROOFTOP", "RANGE_INTERPOLATED", "GEOMETRIC_CENTER", "APPROXIMATE"]
TYPES =
[
  "street_address",               # indicates a precise street address.
  "route",                        # indicates a named route (such as "US 101").
  "intersection",                 # indicates a major intersection, usually of two major roads.
  "political",                    # indicates a political entity. Usually, this type indicates a polygon of some civil administration.
  "country",                      # indicates the national political entity, and is typically the highest order type returned by the Geocoder.
  "administrative_area_level_1",  # indicates a first-order civil entity below the country level. Within the United States, these administrative levels are states. Not all nations exhibit these administrative levels.
  "administrative_area_level_2",  # indicates a second-order civil entity below the country level. Within the United States, these administrative levels are counties. Not all nations exhibit these administrative levels.
  "administrative_area_level_3",  # indicates a third-order civil entity below the country level. This type indicates a minor civil division. Not all nations exhibit these administrative levels.
  "colloquial_area",              # indicates a commonly-used alternative name for the entity.
  "locality",                     # indicates an incorporated city or town political entity.
  "sublocality",                  # indicates an first-order civil entity below a locality
  "neighborhood",                 # indicates a named neighborhood
  "premise",                      # indicates a named location, usually a building or collection of buildings with a common name
  "subpremise",                   # indicates a first-order entity below a named location, usually a singular building within a collection of buildings with a common name
  "postal_code",                  # indicates a postal code as used to address postal mail within the country.
  "natural_feature",              # indicates a prominent natural feature.
  "airport",                      # indicates an airport.
  "park",                         # indicates a named park.
  "point_of_interest",            # indicates a named point of interest. Typically, these "POI"s are prominent local entities that don't easily fit in another category such as "Empire State Building" or "Statue of Liberty."
  "post_box",                     # indicates a specific postal box.
  "street_number",                # indicates the precise street number.
  "floor",                        # indicates the floor of a building address.
  "room",                         # indicates the room of a building address.
]
ACCURATE_TYPES =
[ "street_address", "premise", "subpremise" ]

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(json) ⇒ Location

Returns a new instance of Location.



36
37
38
39
40
41
42
43
44
45
46
47
48
# File 'lib/google_maps/geocoder/location.rb', line 36

def initialize(json)
  self.address_components = json['address_components']
  self.formatted_address = json['formatted_address']
  if geometry_json = json['geometry']
    self.location_type = ActiveSupport::StringInquirer.new(geometry_json['location_type'].downcase)

    if geometry_json['location']
      self.latitude  = BigDecimal(geometry_json['location']['lat'].to_s)
      self.longitude = BigDecimal(geometry_json['location']['lng'].to_s)
    end
  end
  self.types = json['types']
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(method_sym, *args, &block) ⇒ Object



54
55
56
57
58
59
60
61
# File 'lib/google_maps/geocoder/location.rb', line 54

def method_missing(method_sym, *args, &block)
  if TYPES.include?(method_sym.to_s)
    define_address_component_accessor_for_type(method_sym)
    send(method_sym, args.first)
  else
    super
  end
end

Instance Attribute Details

#address_componentsObject

Returns the value of attribute address_components.



34
35
36
# File 'lib/google_maps/geocoder/location.rb', line 34

def address_components
  @address_components
end

#formatted_addressObject

Returns the value of attribute formatted_address.



34
35
36
# File 'lib/google_maps/geocoder/location.rb', line 34

def formatted_address
  @formatted_address
end

#latitudeObject

Returns the value of attribute latitude.



34
35
36
# File 'lib/google_maps/geocoder/location.rb', line 34

def latitude
  @latitude
end

#location_typeObject

Returns the value of attribute location_type.



34
35
36
# File 'lib/google_maps/geocoder/location.rb', line 34

def location_type
  @location_type
end

#longitudeObject

Returns the value of attribute longitude.



34
35
36
# File 'lib/google_maps/geocoder/location.rb', line 34

def longitude
  @longitude
end

#typesObject

Returns the value of attribute types.



34
35
36
# File 'lib/google_maps/geocoder/location.rb', line 34

def types
  @types
end

Instance Method Details

#respond_to?(method_sym, include_private = false) ⇒ Boolean

Returns:

  • (Boolean)


63
64
65
# File 'lib/google_maps/geocoder/location.rb', line 63

def respond_to?(method_sym, include_private = false)
  TYPES.include?(method_sym.to_s) || super
end

#street_address?Boolean

Returns:

  • (Boolean)


50
51
52
# File 'lib/google_maps/geocoder/location.rb', line 50

def street_address?
  (ACCURATE_TYPES & self.types).present?
end