Class Route

java.lang.Object
com.codename1.maps.routing.Route

public final class Route extends Object

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);
  • Constructor Details

    • Route

      public Route(List points, List legs, double distanceMeters, double durationSeconds, String summary)

      Creates a route. Called by RouteService implementations.

      Parameters
      • points: the LatLng road geometry, defensively copied

      • legs: the RouteLegs between consecutive stops, defensively copied

      • distanceMeters: the total length in meters

      • durationSeconds: the total estimated travel time in seconds

      • summary: a short human readable description of the route

  • Method Details

    • getPoints

      public List getPoints()
      The unmodifiable road geometry as LatLng vertices, dense enough to trace the shape of the roads travelled.
    • getLegs

      public List getLegs()
      The unmodifiable RouteLegs, one per pair of consecutive stops.
    • getDistanceMeters

      public double getDistanceMeters()
      The total length of the route in meters.
    • getDurationSeconds

      public double getDurationSeconds()
      The total estimated travel time in seconds.
    • getSummary

      public String getSummary()
      A short human readable description, typically the major roads used.
    • getBounds

      public MapBounds getBounds()

      The smallest MapBounds containing the whole route, or null when the route has no geometry. Pass it to MapSurface.fitBounds(MapBounds, int) 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(List); frame such a route from its own points instead of from these bounds.

    • toPolyline

      public Polyline toPolyline()
      Builds a Polyline tracing this route, ready to hand to MapSurface.addPolyline(Polyline). Each call returns a fresh polyline, so styling one does not affect another.
    • toString

      public String toString()
      Returns a string representation of the object. In general, the toString method returns a string that "textually represents" this object. The result should be a concise but informative representation that is easy for a person to read. It is recommended that all subclasses override this method. The toString method for class Object returns a string consisting of the name of the class of which the object is an instance, the at-sign character `@', and the unsigned hexadecimal representation of the hash code of the object. In other words, this method returns a string equal to the value of: getClass().getName() + '@' + Integer.toHexString(hashCode())
      Overrides:
      toString in class Object