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



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

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

  return 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



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

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

  params = {
    path: path,
    samples: samples
  }

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