Module: GoogleMapsService::Apis::Roads
- Included in:
- Client
- Defined in:
- lib/google_maps_service/apis/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
-
#nearest_roads(points) ⇒ Array
Returns the nearest road segments for provided points.
-
#snap_to_roads(path, interpolate: false) ⇒ Array
Snaps a path to the most likely roads travelled.
-
#snapped_speed_limits(path) ⇒ Hash
Returns the posted speed limit (in km/h) for given road segments.
-
#speed_limits(place_ids) ⇒ Array
Returns the posted speed limit (in km/h) for given road segments.
Instance Method Details
#nearest_roads(points) ⇒ Array
Returns the nearest road segments for provided points. The points passed do not need to be part of a continuous path.
128 129 130 131 132 133 134 135 136 137 138 139 |
# File 'lib/google_maps_service/apis/roads.rb', line 128 def nearest_roads(points) points = GoogleMapsService::Convert.waypoints(points) params = { points: points } return get('/v1/nearestRoads', params, base_url: ROADS_BASE_URL, accepts_client_id: false, custom_response_decoder: method(:extract_roads_body))[:snappedPoints] end |
#snap_to_roads(path, interpolate: false) ⇒ Array
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.
38 39 40 41 42 43 44 45 46 47 48 49 50 51 |
# File 'lib/google_maps_service/apis/roads.rb', line 38 def snap_to_roads(path, 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) ⇒ 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.
94 95 96 97 98 99 100 101 102 103 104 105 |
# File 'lib/google_maps_service/apis/roads.rb', line 94 def snapped_speed_limits(path) 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) ⇒ Array
Returns the posted speed limit (in km/h) for given road segments.
66 67 68 69 70 71 72 73 |
# File 'lib/google_maps_service/apis/roads.rb', line 66 def speed_limits(place_ids) 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 |