Polyline

A polyline is a list of points, where line segments are drawn between consecutive points.
A polyline has the following properties:

Points

The vertices of the line. Line segments are drawn between consecutive points. A
polyline is not closed by default; to form a closed polyline, the start and end
points must be the same.

Width

Line segment width in screen pixels. The width is constant and independent of the
camera's zoom level. The default value is 10.

Color

Line segment color in ARGB format, the same format used by Color. The
default value is black (0xff000000).

Start/end cap

Defines the shape to be used at the start or end of a polyline. Supported cap types:
ButtCap,
SquareCap,
RoundCap
(applicable for solid stroke pattern) and CustomCap
(applicable for any stroke pattern). Default for both start and end: ButtCap.

Joint type

The joint type defines the shape to be used when joining adjacent line segments at all
vertices of the polyline except the start and end vertices. See JointType
for supported joint types. The default value is DEFAULT.

Stroke pattern

Solid (default, represented by null) or a sequence of PatternItem
objects to be repeated along the line. Available PatternItem types:
Gap (defined by
gap length in pixels), Dash (defined
by line width and dash length in pixels) and Dot (circular,
centered on the line, diameter defined by line width in pixels).

Z-Index

The order in which this tile overlay is drawn with respect to other overlays (including
GroundOverlays,
TileOverlays,
Circles, and
Polygons but
not Markers). An
overlay with a larger z-index is drawn over overlays with smaller z-indices. The order of
overlays with the same z-index is arbitrary. The default zIndex is 0.

Visibility

Indicates if the polyline is visible or invisible, i.e., whether it is drawn on the
map. An invisible polyline is not drawn, but retains all of its other properties. The
default is true, i.e., visible.

Geodesic status

Indicates whether the segments of the polyline should be drawn as geodesics, as opposed
to straight lines on the Mercator projection. A geodesic is the shortest path between two
points on the Earth's surface. The geodesic curve is constructed assuming the Earth is a
sphere

An Object associated with the polyline. For example, the
Object can contain data about what the polyline represents. This is easier
than storing a separate Map<Polyline, Object>. As another example, you
can associate a String ID corresponding to the ID from a data set. Google Maps
SDK for Android neither reads nor writes this property.

Methods in this class must be called on the Android UI thread. If not, an IllegalStateException
will be thrown at runtime.

Example

GoogleMap map;
// ... get a map.
// Add a thin red line from London to New York.
Polyline line = map.addPolyline(new PolylineOptions()
.add(new LatLng(51.5, -0.1), new LatLng(40.7, -74.0))
.width(5)
.color(Color.RED));

Returns

Returns

Returns a snapshot of the vertices of this polyline at this time . The list returned
is a copy of the list of vertices and so changes to the polyline's vertices will not be
reflected by this list, nor will changes to this list be reflected by the polyline. To
change the vertices of the polyline, call
setPoints(List).

Parameters

You can use this property to associate an arbitrary Object with this
polyline. For example, the Object can contain data about what the polyline
represents. This is easier than storing a separate Map<Polyline,
Object>. As another example, you can associate a String ID
corresponding to the ID from a data set. Google Maps SDK for Android neither reads nor
writes this property. It is your responsibility to call setTag(null) to
clear the tag when you no longer need it, to prevent memory leaks in your app.

Parameters

tag

if null, the tag is cleared.

public voidsetVisible(boolean
visible)

Sets the visibility of this polyline. When not visible, a polyline is not drawn, but
it keeps all its other properties.

Parameters

visible

if true, then the polyline is visible; if false, it
is not.

public voidsetWidth(float width)

Sets the width of this polyline.

Parameters

width

the width in screen pixels

public voidsetZIndex(float zIndex)

Sets the zIndex of this polyline. Polylines with higher zIndices are drawn above
those with lower indices.