public final class Route
- Object
- Route
A road-following journey returned by a RouteService: the geometry that
traces the actual roads, how long it is, how long it takes, and the legs
and turn-by-turn steps that make it up.
Drawing it is one call – unlike handing raw endpoints to a
Polyline, which would just join them with a straight line:
map.addPolyline(route.toPolyline());
map.fitBounds(route.getBounds(), 40);
Constructors
public Route(List points, List legs, double distanceMeters, double durationSeconds, String summary) | Creates a route. |
Methods
public List getPoints() | The unmodifiable road geometry as LatLng vertices, dense enough to trace the shape of the roads travelled. |
public List getLegs() | The unmodifiable RouteLegs, one per pair of consecutive stops. |
public double getDistanceMeters() | The total length of the route in meters. |
public double getDurationSeconds() | The total estimated travel time in seconds. |
public String getSummary() | A short human readable description, typically the major roads used. |
public MapBounds getBounds() | The smallest MapBounds containing the whole route, or null when the route has no geometry. |
public Polyline toPolyline() | Builds a Polyline tracing this route, ready to hand to MapSurface.addPolyline. |
public String toString() | Returns a string representation of the object. |
Inherited methods
Constructor details
Route
public Route(List points, List legs, double distanceMeters, double durationSeconds, String summary)RouteService implementations.Parameters
Method details
getPoints
public List getPoints()LatLng vertices, dense enough to
trace the shape of the roads travelled.getLegs
public List getLegs()RouteLegs, one per pair of consecutive stops.getDistanceMeters
public double getDistanceMeters()getDurationSeconds
public double getDurationSeconds()getSummary
public String getSummary()getBounds
public MapBounds getBounds()The smallest MapBounds containing the whole route, or null when the
route has no geometry. Pass it to
MapSurface.fitBounds to frame the journey.
Antimeridian caveat: MapBounds is an axis-aligned box whose
longitudes always run west to east, so it cannot describe a span that
wraps past 180 degrees. A route crossing the antimeridian – Fiji to
Samoa, say – therefore reports a box that runs the long way round the
globe, and framing it zooms out to most of the world instead of the
Pacific. This is a limitation of the bounds type rather than of
routing, and it affects anything built from
MapBounds.fromCoordinates; frame such a route from its own points
instead of from these bounds.
toPolyline
public Polyline toPolyline()Polyline tracing this route, ready to hand to
MapSurface.addPolyline. Each call returns a fresh
polyline, so styling one does not affect another.toString
public String toString()