A polyline is a list of points, where line segments are drawn between consecutive points. A polyline has the following properties:
- 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.
- Line segment width in screen pixels. The width is constant and independent of the camera's zoom level. The default value is 10.
- Line segment color in ARGB format, the same format used by
Color. The default value is black (
- The order in which this tile overlay is drawn with respect to other overlays (including
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.
- 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
- If you want to handle events fired when the user clicks the polyline, set this property
true. You can change this value at any time. The default is
false. If this property is set to
true, your app will receive notifications to the
Methods that modify a Polyline must be called on the main thread. If not, an
IllegalStateException will be thrown at runtime.
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));
For more information, read the Shapes developer guide.
Public Constructor Summary
Public Method Summary
public Polyline (IPolylineDelegate delegate)
public boolean equals (Object other)
public int getColor ()
Gets the color of this polyline.
- the color in ARGB format.
public String getId ()
Gets this polyline's id. The id will be unique amongst all Polylines on a map.
- this polyline's id.
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
public float getWidth ()
Gets the width of this polyline.
- the width in screen pixels.
public float getZIndex ()
Gets the zIndex of this polyline.
- the zIndex of the polyline.
public int hashCode ()
public boolean isClickable ()
Gets the clickability of the polyline. If the polyline is clickable, your app
will receive notifications to the
GoogleMap.OnPolylineClickListener when the
user clicks the polyline. The event listener is registered through
trueif the polyline is clickable; otherwise, returns
public boolean isGeodesic ()
Gets whether each segment of the line is drawn as a geodesic or not.
trueif each segment is drawn as a geodesic;
falseif each segment is drawn as a straight line on the Mercator projection.
public boolean isVisible ()
Gets the visibility of this polyline.
- this polyline's visibility.
public void remove ()
Removes this polyline from the map. After a polyline has been removed, the behavior of all its methods is undefined.
public void setClickable (boolean clickable)
Sets the clickability of the polyline. If the polyline is clickable, your app will receive
notifications to the
GoogleMap.OnPolylineClickListener when the user clicks the
polyline. The event listener is registered through
|clickable||New clickability setting for the polyline.|
public void setColor (int color)
Sets the color of this polyline.
|color||the color in ARGB format|
public void setGeodesic (boolean geodesic)
Sets whether to draw each segment of the line as a geodesic or not.
Sets the points of this polyline. This method will take a copy of the points, so further
points will have no effect on this polyline.
|points||an list of
public void setVisible (boolean visible)
Sets the visibility of this polyline. When not visible, a polyline is not drawn, but it keeps all its other properties.
public void setWidth (float width)
Sets the width of this polyline.
|width||the width in screen pixels|
public void setZIndex (float zIndex)
Sets the zIndex of this polyline. Polylines with higher zIndices are drawn above those with lower indices.
|zIndex||the zIndex of this polyline.|