Given in Google Maps JavaScript API - Displaying the DirectionsResult, you may opt to handle yourself the DirectionsResult
which contains the result of the directions of the query or you can choose to automatically handle displaying the result on a map by passing a DirectionsRenderer
object.
To display a DirectionsResult using a DirectionsRenderer, you simply need to do the following:
Create a DirectionsRenderer object.
Call setMap() on the renderer to bind it to the passed map.
Call setDirections() on the renderer, passing it the DirectionsResult. Because the renderer is an MVCObject, it will automatically detect any changes to its properties and update the map when its associated directions have changed.
A DirectionsRenderer
not only handles display of the polyline and any associated markers, but also can handle the textual display of directions as a series of steps. To do so, simply call setPanel()
on your DirectionsRenderer
, passing it the <div>
in which to display this information.
More information and examples to fully understand Google Maps JavaScript API - Directions Service can be obtained from the documentation.