Class: GoogleMapsPlatform::DirectionsStep

Inherits:
BaseModel
  • Object
show all
Defined in:
lib/google_maps_platform/models/directions_step.rb

Overview

Each element in the steps array defines a single step of the calculated directions. A step is the most atomic unit of a direction’s route, containing a single step describing a specific, single instruction on the journey. E.g. “Turn left at W. 4th St.” The step not only describes the instruction but also contains distance and duration information relating to how this step relates to the following step. For example, a step denoted as “Merge onto I-80 West” may contain a duration of “37 miles” and “40 minutes,” indicating that the next step is 37 miles/40 minutes from this step. When using the Directions API to search for transit directions, the steps array will include additional transit details in the form of a transit_details array. If the directions include multiple modes of transportation, detailed directions will be provided for walking or driving steps in an inner steps array. For example, a walking step will include directions from the start and end locations: “Walk to Innes Ave & Fitch St”. That step will include detailed walking directions for that route in the inner steps array, such as: “Head north-west”, “Turn left onto Arelious Walker”, and “Turn left onto Innes Ave”.

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from BaseModel

#check_for_conflict, #process_additional_properties, #process_array, #process_basic_value, #process_hash, #to_hash, #to_json

Constructor Details

#initialize(duration:, end_location:, html_instructions:, polyline:, start_location:, travel_mode:, distance: SKIP, maneuver: SKIP, transit_details: SKIP, steps: SKIP, additional_properties: nil) ⇒ DirectionsStep



136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
# File 'lib/google_maps_platform/models/directions_step.rb', line 136

def initialize(duration:, end_location:, html_instructions:, polyline:,
               start_location:, travel_mode:, distance: SKIP,
               maneuver: SKIP, transit_details: SKIP, steps: SKIP,
               additional_properties: nil)
  # Add additional model properties to the instance

  additional_properties = {} if additional_properties.nil?

  @distance = distance unless distance == SKIP
  @duration = duration
  @end_location = end_location
  @html_instructions = html_instructions
  @maneuver = maneuver unless maneuver == SKIP
  @polyline = polyline
  @start_location = start_location
  @transit_details = transit_details unless transit_details == SKIP
  @travel_mode = travel_mode
  @steps = steps unless steps == SKIP
  @additional_properties = additional_properties
end

Instance Attribute Details

#distanceTextValueObject

An object containing a numeric value and its formatted text representation.



31
32
33
# File 'lib/google_maps_platform/models/directions_step.rb', line 31

def distance
  @distance
end

#durationTextValueObject

An object containing a numeric value and its formatted text representation.



36
37
38
# File 'lib/google_maps_platform/models/directions_step.rb', line 36

def duration
  @duration
end

#end_locationLatLngLiteral

An object describing a specific location with Latitude and Longitude in decimal degrees.



41
42
43
# File 'lib/google_maps_platform/models/directions_step.rb', line 41

def end_location
  @end_location
end

#html_instructionsString

Contains formatted instructions for this step, presented as an HTML text string. This content is meant to be read as-is. Do not programmatically parse this display-only content.



47
48
49
# File 'lib/google_maps_platform/models/directions_step.rb', line 47

def html_instructions
  @html_instructions
end

#maneuverManeuver

Contains the action to take for the current step (turn left, merge, straight, etc.). Values are subject to change, and new values may be introduced without prior notice.



53
54
55
# File 'lib/google_maps_platform/models/directions_step.rb', line 53

def maneuver
  @maneuver
end

#polylineDirectionsPolyline

[Polyline encoding](developers.google.com/maps/documentation/utilities/polyl inealgorithm) is a lossy compression algorithm that allows you to store a series of coordinates as a single string. Point coordinates are encoded using signed values. If you only have a few static points, you may also wish to use the interactive polyline encoding utility. The encoding process converts a binary value into a series of character codes for ASCII characters using the familiar base64 encoding scheme: to ensure proper display of these characters, encoded values are summed with 63 (the ASCII character ‘?’) before converting them into ASCII. The algorithm also checks for additional character codes for a given point by checking the least significant bit of each byte group; if this bit is set to 1, the point is not yet fully formed and additional data must follow. Additionally, to conserve space, points only include the offset from the previous point (except of course for the first point). All points are encoded in Base64 as signed integers, as latitudes and longitudes are signed values. The encoding format within a polyline needs to represent two coordinates representing latitude and longitude to a reasonable precision. Given a maximum longitude of +/- 180 degrees to a precision of 5 decimal places (180.00000 to -180.00000), this results in the need for a 32 bit signed binary integer value.



77
78
79
# File 'lib/google_maps_platform/models/directions_step.rb', line 77

def polyline
  @polyline
end

#start_locationLatLngLiteral

An object describing a specific location with Latitude and Longitude in decimal degrees.



82
83
84
# File 'lib/google_maps_platform/models/directions_step.rb', line 82

def start_location
  @start_location
end

#stepsObject

Contains detailed directions for walking or driving steps in transit directions. Substeps are only available when travel_mode is set to “transit”. The inner steps array is of the same type as steps.



103
104
105
# File 'lib/google_maps_platform/models/directions_step.rb', line 103

def steps
  @steps
end

#transit_detailsDirectionsTransitDetails

Additional information that is not relevant for other modes of transportation.



87
88
89
# File 'lib/google_maps_platform/models/directions_step.rb', line 87

def transit_details
  @transit_details
end

#travel_modeTravelMode

  • DRIVING (default) indicates calculation using the road network.

  • BICYCLING requests calculation for bicycling via bicycle paths &

preferred streets (where available).

  • TRANSIT requests calculation via public transit routes (where

available).

  • WALKING requests calculation for walking via pedestrian paths &

sidewalks (where available).



97
98
99
# File 'lib/google_maps_platform/models/directions_step.rb', line 97

def travel_mode
  @travel_mode
end

Class Method Details

.from_hash(hash) ⇒ Object

Creates an instance of the object from a hash.



157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
# File 'lib/google_maps_platform/models/directions_step.rb', line 157

def self.from_hash(hash)
  return nil unless hash

  # Extract variables from the hash.

  duration = TextValueObject.from_hash(hash['duration']) if hash['duration']
  end_location = LatLngLiteral.from_hash(hash['end_location']) if hash['end_location']
  html_instructions =
    hash.key?('html_instructions') ? hash['html_instructions'] : nil
  polyline = DirectionsPolyline.from_hash(hash['polyline']) if hash['polyline']
  start_location = LatLngLiteral.from_hash(hash['start_location']) if hash['start_location']
  travel_mode = hash.key?('travel_mode') ? hash['travel_mode'] : nil
  distance = TextValueObject.from_hash(hash['distance']) if hash['distance']
  maneuver = hash.key?('maneuver') ? hash['maneuver'] : SKIP
  transit_details = DirectionsTransitDetails.from_hash(hash['transit_details']) if
    hash['transit_details']
  steps = hash.key?('steps') ? hash['steps'] : SKIP

  # Create a new hash for additional properties, removing known properties.

  new_hash = hash.reject { |k, _| names.value?(k) }

  additional_properties = APIHelper.get_additional_properties(
    new_hash, proc { |value| value }
  )

  # Create object from extracted values.

  DirectionsStep.new(duration: duration,
                     end_location: end_location,
                     html_instructions: html_instructions,
                     polyline: polyline,
                     start_location: start_location,
                     travel_mode: travel_mode,
                     distance: distance,
                     maneuver: maneuver,
                     transit_details: transit_details,
                     steps: steps,
                     additional_properties: additional_properties)
end

.namesObject

A mapping from model property names to API property names.



106
107
108
109
110
111
112
113
114
115
116
117
118
119
# File 'lib/google_maps_platform/models/directions_step.rb', line 106

def self.names
  @_hash = {} if @_hash.nil?
  @_hash['distance'] = 'distance'
  @_hash['duration'] = 'duration'
  @_hash['end_location'] = 'end_location'
  @_hash['html_instructions'] = 'html_instructions'
  @_hash['maneuver'] = 'maneuver'
  @_hash['polyline'] = 'polyline'
  @_hash['start_location'] = 'start_location'
  @_hash['transit_details'] = 'transit_details'
  @_hash['travel_mode'] = 'travel_mode'
  @_hash['steps'] = 'steps'
  @_hash
end

.nullablesObject

An array for nullable fields



132
133
134
# File 'lib/google_maps_platform/models/directions_step.rb', line 132

def self.nullables
  []
end

.optionalsObject

An array for optional fields



122
123
124
125
126
127
128
129
# File 'lib/google_maps_platform/models/directions_step.rb', line 122

def self.optionals
  %w[
    distance
    maneuver
    transit_details
    steps
  ]
end

Instance Method Details

#inspectObject

Provides a debugging-friendly string with detailed object information.



206
207
208
209
210
211
212
213
214
# File 'lib/google_maps_platform/models/directions_step.rb', line 206

def inspect
  class_name = self.class.name.split('::').last
  "<#{class_name} distance: #{@distance.inspect}, duration: #{@duration.inspect},"\
  " end_location: #{@end_location.inspect}, html_instructions: #{@html_instructions.inspect},"\
  " maneuver: #{@maneuver.inspect}, polyline: #{@polyline.inspect}, start_location:"\
  " #{@start_location.inspect}, transit_details: #{@transit_details.inspect}, travel_mode:"\
  " #{@travel_mode.inspect}, steps: #{@steps.inspect}, additional_properties:"\
  " #{@additional_properties}>"
end

#to_sObject

Provides a human-readable string representation of the object.



196
197
198
199
200
201
202
203
# File 'lib/google_maps_platform/models/directions_step.rb', line 196

def to_s
  class_name = self.class.name.split('::').last
  "<#{class_name} distance: #{@distance}, duration: #{@duration}, end_location:"\
  " #{@end_location}, html_instructions: #{@html_instructions}, maneuver: #{@maneuver},"\
  " polyline: #{@polyline}, start_location: #{@start_location}, transit_details:"\
  " #{@transit_details}, travel_mode: #{@travel_mode}, steps: #{@steps},"\
  " additional_properties: #{@additional_properties}>"
end