Class: GoogleMaps::Services::Elevation
- Inherits:
-
Object
- Object
- GoogleMaps::Services::Elevation
- Defined in:
- lib/googlemaps/services/elevation.rb
Overview
Performs requests to the Google Maps Elevation API.
Instance Attribute Summary collapse
-
#client ⇒ Symbol
The HTTP client.
Instance Method Summary collapse
-
#initialize(client) ⇒ Elevation
constructor
A new instance of Elevation.
-
#query(locations: nil, path: nil, samples: 0) ⇒ Array, Nokogiri::XML::NodeSet
Provides elevation data for locations provided on the surface of the earth, including depth locations on the ocean floor (which return negative values).
Constructor Details
#initialize(client) ⇒ Elevation
Returns a new instance of Elevation.
16 17 18 |
# File 'lib/googlemaps/services/elevation.rb', line 16 def initialize(client) self.client = client end |
Instance Attribute Details
#client ⇒ Symbol
Returns The HTTP client.
14 15 16 |
# File 'lib/googlemaps/services/elevation.rb', line 14 def client @client end |
Instance Method Details
#query(locations: nil, path: nil, samples: 0) ⇒ Array, Nokogiri::XML::NodeSet
Provides elevation data for locations provided on the surface of the earth, including depth locations on the ocean floor (which return negative values). Provides elevation data sampled along a path on the surface of the earth.
29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 |
# File 'lib/googlemaps/services/elevation.rb', line 29 def query(locations: nil, path: nil, samples: 0) params = {} if locations params['locations'] = Convert.shortest_path(locations) end if path if path.instance_of? String path = "enc:#{path}" elsif path.instance_of? Array path = Convert.shortest_path(path) else raise TypeError, 'Path should be either a String or an Array.' end params = {'path' => path, 'samples' => samples} end if path && locations raise StandardError, 'Should not specify both path and locations.' end case self.client.response_format when :xml self.client .request(url: '/maps/api/elevation/xml', params: params) .xpath('//result') when :json self.client .request(url: '/maps/api/elevation/json', params: params) .fetch('results', []) else raise StandardError, 'Unsupported response format. Should be either :json or :xml.' end end |