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 |
# File 'lib/google_maps_service/roads.rb', line 29 def snap_to_roads(path: nil, interpolate: false) path = GoogleMapsService::Convert.waypoints(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.
69 70 71 72 73 74 75 76 77 78 79 80 |
# File 'lib/google_maps_service/roads.rb', line 69 def snapped_speed_limits(path: nil) path = GoogleMapsService::Convert.waypoints(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.
49 50 51 52 53 54 55 56 |
# File 'lib/google_maps_service/roads.rb', line 49 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 |