Polyline | Android Developers

Quicknav Quicknav
Links

- Google Play Developer Console
- Android Developers Blog
- About Android

Android Sites

- Android.com
- Android Developers
- Android Open Source Project

Language
close

- - About
  - Wear
  - TV
  - Auto
- - Get Started
  - Devices
  - Style
  - Patterns
  - Building Blocks
  - Downloads
  - Videos
- - Training
  - API Guides
  - Reference
  - Tools
  - Google Services
  - Samples
- - Google Play
  - Essentials
  - Get Users
  - Engage & Retain
  - Monetize
  - Tools & Reference
  - Developer Stories

## Results

Loading...
Summary: Ctors | Methods | Inherited Methods | [Expand All]
public final class

# Polyline

extends Object

java.lang.Object
↳ | com.google.android.gms.maps.model.Polyline

## Class Overview

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`).
Z-Index
  The order in which this tile overlay is drawn with respect to other overlays (including `GroundOverlay`s, `TileOverlay`s, `Circle`s, and `Polygon`s but not `Marker`s). 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

Methods that modify a Polyline must be called on the main 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));

### Developer Guide

For more information, read the Shapes developer guide.

## Summary

Public Constructors
| Polyline(IPolylineDelegate delegate)

Public Methods
boolean | equals(Object other)
int | getColor() Gets the color of this polyline.
String | getId() Gets this polyline's id.
List<LatLng> | getPoints() Returns a snapshot of the vertices of this polyline at this time .
float | getWidth() Gets the width of this polyline.
float | getZIndex() Gets the zIndex of this polyline.
int | hashCode()
boolean | isGeodesic() Gets whether each segment of the line is drawn as a geodesic or not.
boolean | isVisible() Gets the visibility of this polyline.
void | remove() Removes this polyline from the map.
void | setColor(int color) Sets the color of this polyline.
void | setGeodesic(boolean geodesic) Sets whether to draw each segment of the line as a geodesic or not.
void | setPoints(List<LatLng> points) Sets the points of this polyline.
void | setVisible(boolean visible) Sets the visibility of this polyline.
void | setWidth(float width) Sets the width of this polyline.
void | setZIndex(float zIndex) Sets the zIndex of this polyline.

[Expand] Inherited Methods
From class java.lang.Object
Object | clone()
boolean | equals(Object arg0)
void | finalize()
final Class<?> | getClass()
int | hashCode()
final void | notify()
final void | notifyAll()
String | toString()
final void | wait()
final void | wait(long arg0, int arg1)
final void | wait(long arg0)

## Public Constructors

#### public Polyline (IPolylineDelegate delegate)

## Public Methods

#### public boolean equals (Object other)

#### public int getColor ()

Gets the color of this polyline.

##### Returns

- the color in ARGB format.

#### public String getId ()

Gets this polyline's id. The id will be unique amongst all Polylines on a map.

##### Returns

- this polyline's id.

#### public List<LatLng> getPoints ()

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)`.

#### public float getWidth ()

Gets the width of this polyline.

##### Returns

- the width in screen pixels.

#### public float getZIndex ()

Gets the zIndex of this polyline.

##### Returns

- the zIndex of the polyline.

#### public int hashCode ()

#### public boolean isGeodesic ()

Gets whether each segment of the line is drawn as a geodesic or not.

##### Returns

- `true` if each segment is drawn as a geodesic; `false` if each segment is drawn as a straight line on the Mercator projection.

#### public boolean isVisible ()

Gets the visibility of this polyline.

##### Returns

- 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 setColor (int color)

Sets the color of this polyline.

##### Parameters

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.

##### Parameters

geodesic | if `true`, then each segment is drawn as a geodesic; if `false`, each segment is drawn as a straight line on the Mercator projection.

#### public void setPoints (List<LatLng> points)

Sets the points of this polyline. This method will take a copy of the points, so further mutations to `points` will have no effect on this polyline.

##### Parameters

points | an list of `LatLng`s that are the vertices of the polyline.

#### 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.

##### Parameters

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

#### public void setWidth (float width)

Sets the width of this polyline.

##### Parameters

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.

##### Parameters

zIndex | the zIndex of this polyline.