Class: GoogleMaps::Services::Roads
- Inherits:
-
Object
- Object
- GoogleMaps::Services::Roads
- Includes:
- Exceptions
- Defined in:
- lib/googlemaps/services/roads.rb
Overview
Performs requests to the Google Maps Roads API.
Instance Attribute Summary collapse
-
#client ⇒ Symbol
The HTTP client.
Instance Method Summary collapse
-
#initialize(client) ⇒ Roads
constructor
A new instance of Roads.
-
#nearest_roads(points:) ⇒ Array
Find the closest road segments for each point.
-
#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.
Constructor Details
#initialize(client) ⇒ Roads
Returns a new instance of Roads.
16 17 18 |
# File 'lib/googlemaps/services/roads.rb', line 16 def initialize(client) self.client = client end |
Instance Attribute Details
#client ⇒ Symbol
Returns the HTTP client.
14 15 16 |
# File 'lib/googlemaps/services/roads.rb', line 14 def client @client end |
Instance Method Details
#nearest_roads(points:) ⇒ Array
Find the closest road segments for each point. Takes up to 100 independent coordinates, and returns the closest road segment for each point. The points passed do not need to be part of a continuous path.
81 82 83 84 85 86 87 88 |
# File 'lib/googlemaps/services/roads.rb', line 81 def nearest_roads(points:) params = {'points' => Convert.piped_location(points)} self.client .request(url: '/v1/nearestRoads', params: params, base_url: Constants::ROADS_BASE_URL, accepts_clientid: false, extract_body: lambda(&method(:_roads_extract))) .fetch('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.
30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/googlemaps/services/roads.rb', line 30 def snap_to_roads(path:, interpolate: false) params = {'path' => Convert.piped_location(path)} if interpolate params['interpolate'] = 'true' end self.client .request(url: '/v1/snapToRoads', params: params, base_url: Constants::ROADS_BASE_URL, accepts_clientid: false, extract_body: lambda(&method(:_roads_extract))) .fetch('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.
66 67 68 69 70 71 72 |
# File 'lib/googlemaps/services/roads.rb', line 66 def snapped_speed_limits(path:) params = {'path' => Convert.piped_location(path)} self.client .request(url: '/v1/speedLimits', params: params, base_url: Constants::ROADS_BASE_URL, accepts_clientid: false, extract_body: lambda(&method(:_roads_extract))) end |
#speed_limits(place_ids:) ⇒ Array
Returns the posted speed limit (in km/h) for given road segments.
49 50 51 52 53 54 55 56 57 58 |
# File 'lib/googlemaps/services/roads.rb', line 49 def speed_limits(place_ids:) raise StandardError, "#{__method__.to_s} expected an Array for place_ids." unless place_ids.is_a? Array params = {'placeId' => place_ids} self.client .request(url: '/v1/speedLimits', params: params, base_url: Constants::ROADS_BASE_URL, accepts_clientid: false, extract_body: lambda(&method(:_roads_extract))) .fetch('speedLimits', []) end |