Class: GoogleMaps::Services::ReverseGeocode
- Inherits:
-
Object
- Object
- GoogleMaps::Services::ReverseGeocode
- Defined in:
- lib/googlemaps/services/geocoding.rb
Overview
Performs requests to the Google Maps Geocoding API.
Instance Attribute Summary collapse
Instance Method Summary collapse
-
#initialize(client) ⇒ ReverseGeocode
constructor
A new instance of ReverseGeocode.
-
#query(latlng:, result_type: nil, location_type: nil, language: nil) ⇒ String
Reverse geocoding is the process of converting geographic coordinates into a human-readable address.
Constructor Details
#initialize(client) ⇒ ReverseGeocode
Returns a new instance of ReverseGeocode.
79 80 81 |
# File 'lib/googlemaps/services/geocoding.rb', line 79 def initialize(client) self.client = client end |
Instance Attribute Details
#client ⇒ Object
77 78 79 |
# File 'lib/googlemaps/services/geocoding.rb', line 77 def client @client end |
Instance Method Details
#query(latlng:, result_type: nil, location_type: nil, language: nil) ⇒ String
Reverse geocoding is the process of converting geographic coordinates into a human-readable address.
91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 |
# File 'lib/googlemaps/services/geocoding.rb', line 91 def query(latlng:, result_type: nil, location_type: nil, language: nil) # Check if latlng param is a place_id string. # 'place_id' strings do not contain commas; latlng strings do. if latlng.is_a?(String) && !latlng.include?(",") params = {'place_id' => latlng} else params = {'latlng' => Convert.to_latlng(latlng)} end if result_type params['result_type'] = Convert.join_array('|', result_type) end if location_type params['location_type'] = Convert.join_array('|', location_type) end if language params['language'] = language end case self.client.response_format when :xml self.client .request(url: '/maps/api/geocode/xml', params: params) .xpath('//result') when :json self.client .request(url: '/maps/api/geocode/json', params: params) .fetch('results', []) else raise StandardError, 'Unsupported response format. Should be either :json or :xml.' end end |