Module: GoogleMapsService::Elevation

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

Overview

Performs requests to the Google Maps Elevation API.

Instance Method Summary collapse

Instance Method Details

#elevation(locations: nil) ⇒ Array

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

Parameters:

  • locations (Array) (defaults to: nil)

    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



15
16
17
18
19
20
21
22
23
24
# File 'lib/google_maps_service/elevation.rb', line 15

def elevation(locations: nil)
  params = {}
  if locations.kind_of?(Array) and locations.length == 2 and not locations[0].kind_of?(Array)
    locations = [locations]
  end

  params[:locations] = _convert_locations(locations)

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

#elevation_along_path(path: nil, samples: nil) ⇒ Array

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

Parameters:

  • path (String, Array) (defaults to: nil)

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

  • samples (Integer) (defaults to: nil)

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

Returns:

  • (Array)

    Array of elevation data responses



36
37
38
39
40
41
42
43
44
45
46
47
48
49
# File 'lib/google_maps_service/elevation.rb', line 36

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

  params = {
    path: path,
    samples: samples
  }

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