Module: GoogleMapsService::Roads

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

Overview

Performs requests to the Google Maps Roads API.“”“

Constant Summary collapse

ROADS_BASE_URL =

Base URL of Google Maps Roads API

"https://roads.googleapis.com"

Instance Method Summary collapse

Instance Method Details

#snap_to_roads(path: nil, interpolate: false) ⇒ Object

Snaps a path to the most likely roads travelled.

Takes up to 100 GPS points collected along a route, and returns a similar set of data with the points snapped to the most likely roads the vehicle was traveling along.

:type path: list

:type interpolate: bool

:rtype: A list of snapped points.

Parameters:

  • []

    path The path to be snapped. A list of latitude/longitude tuples.

  • []

    interpolate Whether to interpolate a path to include all points forming the full road-geometry. When true, additional interpolated points will also be returned, resulting in a path that smoothly follows the geometry of the road, even around corners and through tunnels. Interpolated paths may contain more points than the original path.



29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/google_maps_service/roads.rb', line 29

def snap_to_roads(path: nil, interpolate: false)
  if path.kind_of?(Array) and path.length == 2 and not path[0].kind_of?(Array)
    path = [path]
  end

  path = _convert_path(path)

  params = {
    path: path
  }

  params[:interpolate] = "true" if interpolate

  return get("/v1/snapToRoads", params,
             base_url: ROADS_BASE_URL,
             accepts_client_id: false,
             custom_response_decoder: method(:extract_roads_body))[:snappedPoints]
end

#snapped_speed_limits(path: nil) ⇒ Hash

Returns the posted speed limit (in km/h) for given road segments.

The provided points will first be snapped to the most likely roads the vehicle was traveling along.

Parameters:

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

    The path of points to be snapped. A list of (or single) latitude/longitude tuples.

Returns:

  • (Hash)

    a dict with both a list of speed limits and a list of the snapped points.



73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
# File 'lib/google_maps_service/roads.rb', line 73

def snapped_speed_limits(path: nil)

  if path.kind_of?(Array) and path.length == 2 and not path[0].kind_of?(Array)
    path = [path]
  end

  path = _convert_path(path)

  params = {
    path: path
  }

  return get("/v1/speedLimits", params,
             base_url: ROADS_BASE_URL,
             accepts_client_id: false,
             custom_response_decoder: method(:extract_roads_body))
end

#speed_limits(place_ids: nil) ⇒ Object

Returns the posted speed limit (in km/h) for given road segments.

Parameters:

  • place_ids (String, Array<String>) (defaults to: nil)

    The Place ID of the road segment. Place IDs are returned by the snap_to_roads function. You can pass up to 100 Place IDs.

Returns:

  • Array of speed limits.



53
54
55
56
57
58
59
60
# File 'lib/google_maps_service/roads.rb', line 53

def speed_limits(place_ids: nil)
  params = GoogleMapsService::Convert.as_list(place_ids).map { |place_id| ["placeId", place_id] }

  return get("/v1/speedLimits", params,
             base_url: ROADS_BASE_URL,
             accepts_client_id: false,
             custom_response_decoder: method(:extract_roads_body))[:speedLimits]
end