public final class Polyline

  1. Object
  2. MapObject
  3. Polyline

A connected sequence of line segments drawn on a map. Add one through MapSurface.addPolyline(Polyline).

A polyline joins the vertices you give it with straight segments; it knows nothing about roads. To draw a route that follows the road network, ask a routing service for the road geometry and draw that – see Routing, or decode a geometry you fetched yourself with fromEncoded(String).

Constructors

public Polyline()Creates an empty polyline; append vertices with addPoint(LatLng).
public Polyline(LatLng[] pts)Creates a polyline through the supplied vertices (defensively copied).

Methods

public static Polyline fromEncoded(String encoded)Creates a polyline from an encoded polyline geometry at PolylineCodec’s default precision – the shape virtually every directions API returns for a route.
public static Polyline fromEncoded(String encoded, int precision)Creates a polyline from an encoded polyline geometry at an explicit decimal precision (5 for the classic format, 6 for polyline6).
public Polyline addPoint(LatLng point)Appends a vertex.
public List getPoints()The live list of vertices (LatLng).
public int getStrokeColor()The stroke color as 0xRRGGBB.
public Polyline setStrokeColor(int strokeColor)Sets the stroke color as 0xRRGGBB.
public int getStrokeWidth()The stroke width in pixels.
public Polyline setStrokeWidth(int strokeWidth)Sets the stroke width in pixels.
public int getStrokeAlpha()The stroke opacity in [0,255].
public Polyline setStrokeAlpha(int strokeAlpha)Sets the stroke opacity in [0,255].
public boolean isVisible()Whether the polyline is rendered.
public Polyline setVisible(boolean visible)Shows or hides the polyline.

Inherited methods

Constructor details

Polyline

public Polyline()
Creates an empty polyline; append vertices with addPoint(LatLng).

Polyline

public Polyline(LatLng[] pts)
Creates a polyline through the supplied vertices (defensively copied).

Method details

fromEncoded

public static Polyline fromEncoded(String encoded)
Creates a polyline from an encoded polyline geometry at PolylineCodec’s default precision – the shape virtually every directions API returns for a route.

fromEncoded

public static Polyline fromEncoded(String encoded, int precision)

Creates a polyline from an encoded polyline geometry at an explicit decimal precision (5 for the classic format, 6 for polyline6).

Throws IllegalArgumentException when precision falls outside 1 to 10; a precision that cannot scale coordinates sensibly would otherwise decode into a line drawn in the wrong place. See PolylineCodec.

addPoint

public Polyline addPoint(LatLng point)
Appends a vertex.

getPoints

public List getPoints()
The live list of vertices (LatLng).

getStrokeColor

public int getStrokeColor()
The stroke color as 0xRRGGBB.

setStrokeColor

public Polyline setStrokeColor(int strokeColor)
Sets the stroke color as 0xRRGGBB.

getStrokeWidth

public int getStrokeWidth()
The stroke width in pixels.

setStrokeWidth

public Polyline setStrokeWidth(int strokeWidth)
Sets the stroke width in pixels.

getStrokeAlpha

public int getStrokeAlpha()
The stroke opacity in [0,255].

setStrokeAlpha

public Polyline setStrokeAlpha(int strokeAlpha)
Sets the stroke opacity in [0,255].

isVisible

public boolean isVisible()
Whether the polyline is rendered.

setVisible

public Polyline setVisible(boolean visible)
Shows or hides the polyline.