Class: GoogleMapsPlatform::ElevationApiController

Inherits:
BaseController show all
Defined in:
lib/google_maps_platform/controllers/elevation_api_controller.rb

Overview

ElevationApiController

Constant Summary

Constants inherited from BaseController

BaseController::GLOBAL_ERRORS

Instance Attribute Summary

Attributes inherited from BaseController

#config, #http_call_back

Instance Method Summary collapse

Methods inherited from BaseController

#initialize, #new_parameter, #new_request_builder, #new_response_handler, user_agent, user_agent_parameters

Constructor Details

This class inherits a constructor from GoogleMapsPlatform::BaseController

Instance Method Details

#elevation(locations: nil, path: nil, samples: nil) ⇒ ApiResponse

The Elevation API provides a simple interface to query locations on the earth for elevation data. Additionally, you may request sampled elevation data along paths, allowing you to calculate elevation changes along routes. With the Elevation API, you can develop hiking and biking applications, positioning applications, or low resolution surveying applications. Elevation data is available for all locations on the surface of the earth, including depth locations on the ocean floor (which return negative values). In those cases where Google does not possess exact elevation measurements at the precise location you request, the service interpolates and returns an averaged value using the four nearest locations. Elevation values are expressed relative to local mean sea level (LMSL). Requests to the Elevation API utilize different parameters based on whether the request is for discrete locations or for an ordered path. For discrete locations, requests for elevation return data on the specific locations passed in the request; for paths, elevation requests are instead sampled along the given path. are indicated through use of the locations parameter, indicating elevation requests for the specific locations passed as latitude/longitude values. The locations parameter may take the following arguments: - A single coordinate: ‘locations=40.714728,-73.998672` - An array of coordinates separated using the pipe (’|‘) character: “` locations=40.714728,-73.998672|-34.397,150.644 “` - A set of encoded coordinates using the [Encoded Polyline Algorithm](developers.google.com/maps/documentation/utilities/poly linealgorithm): “` locations=enc:gfo}EtohhU “` Latitude and longitude coordinate strings are defined using numerals within a comma-separated text string. For example, “40.714728,-73.998672” is a valid locations value. Latitude and longitude values must correspond to a valid location on the face of the earth. Latitudes can take any value between -90 and 90 while longitude values can take any value between -180 and 180. If you specify an invalid latitude or longitude value, your request will be rejected as a bad request. You may pass any number of multiple coordinates within an array or encoded polyline, while still constructing a valid URL. Note that when passing multiple coordinates, the accuracy of any returned data may be of lower resolution than when requesting data for a single coordinate. separated `latitude,longitude` strings. set.



52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
# File 'lib/google_maps_platform/controllers/elevation_api_controller.rb', line 52

def elevation(locations: nil,
              path: nil,
              samples: nil)
  @api_call
    .request(new_request_builder(HttpMethodEnum::GET,
                                 '/maps/api/elevation/json',
                                 Server::DEFAULT)
               .query_param(new_parameter(locations, key: 'locations'))
               .query_param(new_parameter(path, key: 'path'))
               .query_param(new_parameter(samples, key: 'samples'))
               .header_param(new_parameter('application/json', key: 'accept'))
               .auth(Single.new('ApiKeyAuth')))
    .response(new_response_handler
                .deserializer(APIHelper.method(:custom_type_deserializer))
                .deserialize_into(MapsApiElevationJsonResponse.method(:from_hash))
                .is_api_response(true))
    .execute
end