Module: GoogleMapsService::Apis::Elevation

Included in:
Client
Defined in:
lib/google_maps_service/apis/elevation.rb

Overview

Performs requests to the Google Maps Elevation API.

Instance Method Summary collapse

Instance Method Details

#elevation(locations) ⇒ Array

Provides elevation data for locations provided on the surface of the earth, including depth locations on the ocean floor (which return negative values).

Examples:

Single point elevation

results = client.elevation({latitude: 40.714728, longitude: -73.998672})

Multiple points elevation

locations = [[40.714728, -73.998672], [-34.397, 150.644]]
results = client.elevation(locations)

Parameters:

  • locations (Array)

    A single latitude/longitude hash, or an array of latitude/longitude hash from which you wish to calculate elevation data.

Returns:

  • (Array)

    Array of elevation data responses



20
21
22
23
24
25
26
# File 'lib/google_maps_service/apis/elevation.rb', line 20

def elevation(locations)
  params = {
    locations: GoogleMapsService::Convert.waypoints(locations)
  }

  get("/maps/api/elevation/json", params)[:results]
end

#elevation_along_path(path, samples) ⇒ Array

Provides elevation data sampled along a path on the surface of the earth.

Examples:

Elevation along path

locations = [[40.714728, -73.998672], [-34.397, 150.644]]
results = client.elevation_along_path(locations, 5)

Parameters:

  • path (String, Array)

    A encoded polyline string, or a list of latitude/longitude pairs from which you wish to calculate elevation data.

  • samples (Integer)

    The number of sample points along a path for which to return elevation data.

Returns:

  • (Array)

    Array of elevation data responses



41
42
43
44
45
46
47
48
49
50
51
52
53
54
# File 'lib/google_maps_service/apis/elevation.rb', line 41

def elevation_along_path(path, samples)
  path = if path.is_a?(String)
    "enc:%s" % path
  else
    GoogleMapsService::Convert.waypoints(path)
  end

  params = {
    path: path,
    samples: samples
  }

  get("/maps/api/elevation/json", params)[:results]
end