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
-
#snap_to_roads(path: nil, interpolate: false) ⇒ Object
Snaps a path to the most likely roads travelled.
-
#snapped_speed_limits(path: nil) ⇒ Hash
Returns the posted speed limit (in km/h) for given road segments.
-
#speed_limits(place_ids: nil) ⇒ Object
Returns the posted speed limit (in km/h) for given road segments.
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.
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.
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.
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 |