Circle

public final classCircleextendsObject

A circle on the earth's surface (spherical cap).

A circle has the following properties.

Center
The center of the Circle is specified as aLatLng.
Radius
The radius of the circle, specified in meters. It should be zero or greater.
Stroke Width
The width of the circle's outline in screen pixels. The width is constant and independent of the camera's zoom level. The default value is 10.
Stroke Color
The color of the circle outline in ARGB format, the same format used byColor.The default value is black (0xff000000).
Stroke pattern
Solid (default, represented bynull) or a sequence ofPatternItem objects to be repeated along the circle's outline. AvailablePatternItem types:Gap(defined by gap length in pixels),Dash(defined by stroke width and dash length in pixels) andDot(circular, centered on the circle's outline, diameter defined by stroke width in pixels).
Fill Color
The color of the circle fill in ARGB format, the same format used byColor.The default value is transparent (0x00000000).
Z-Index
The order in which this tile overlay is drawn with respect to other overlays (including GroundOverlays, TileOverlays, Polylines, andPolygons but notMarkers). 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 circle is visible or invisible, i.e., whether it is drawn on the map. An invisible circle is not drawn, but retains all of its other properties. The default is true,i.e., visible.
Tag
AnObjectassociated with the circle. For example, theObject can contain data about what the circle represents. This is easier than storing a separate Map<Circle, Object>.As another example, you can associate a StringID 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, anIllegalStateException will be thrown at runtime.

Example

GoogleMap map;
//... get a map.
// Add a circle in Sydney
Circle circle = map.addCircle(new CircleOptions()
.center(new LatLng(-33.87365, 151.20689))
.radius(10000)
.strokeColor(Color.RED)
.fillColor(Color.BLUE));

Note that the current map renderer is unable to draw the circle fill if the circle encompasses either the North or South pole. However, the outline will still be drawn correctly.

Developer Guide

For more information, read theShapesdeveloper guide.

Public Method Summary

LatLng
getCenter()
Returns the center as aLatLng.
int
getFillColor()
Returns the fill color of this Circle.
String
getId()
Gets this circle's id.
double
getRadius()
Returns the circle's radius, in meters.
int
getStrokeColor()
Returns the stroke color.
List<PatternItem>
getStrokePattern()
Returns the stroke pattern of this circle's outline.
float
getStrokeWidth()
Returns the stroke width.
Object
getTag()
Gets the tag for the circle.
float
getZIndex()
Returns the zIndex.
boolean
isClickable()
Gets the clickability of the circle.
boolean
isVisible()
Checks whether the circle is visible.
void
remove()
Removes this circle from the map.
void
setCenter(LatLng center)
Sets the center using aLatLng.
void
setClickable(boolean clickable)
Sets the clickability of the circle.
void
setFillColor(int color)
Sets the fill color.
void
setRadius(double radius)
Sets the radius in meters.
void
setStrokeColor(int color)
Sets the stroke color.
void
setStrokePattern(List<PatternItem> pattern)
Sets the stroke pattern of the circle's outline.
void
setStrokeWidth(float width)
Sets the stroke width.
void
setTag(Objecttag)
Sets the tag for the circle.
void
setVisible(boolean visible)
Sets the visibility of the circle.
void
setZIndex(float zIndex)
Sets the zIndex.

Inherited Method Summary

Public Methods

publicLatLng getCenter()

Returns the center as aLatLng.

Returns
  • The geographic center as aLatLng.

public intgetFillColor()

Returns the fill color of this Circle.

Returns
  • The fill color of the circle in ARGB format.

publicStringgetId()

Gets this circle's id. The id will be unique amongst all Circles on a map.

public doublegetRadius()

Returns the circle's radius, in meters.

Returns
  • The radius in meters.

public intgetStrokeColor()

Returns the stroke color.

Returns
  • The color of the circle in ARGB format.

publicList<PatternItem> getStrokePattern()

Returns the stroke pattern of this circle's outline.

Returns
  • the stroke pattern, ornullif default solid stroke pattern is used.

public floatgetStrokeWidth()

Returns the stroke width.

Returns
  • The width in screen pixels.

publicObjectgetTag()

Gets the tag for the circle.

Returns

public floatgetZIndex()

Returns the zIndex.

Returns
  • The zIndex of this circle.

public booleanisClickable()

Gets the clickability of the circle. If the circle is clickable, your app will receive notifications to theGoogleMap.OnCircleClickListener when the user clicks the circle. The event listener is registered through GoogleMap.setOnCircleClickListener(GoogleMap.OnCircleClickListener).

Returns
  • trueif the circle is clickable;falseif it is not clickable.

public booleanisVisible()

Checks whether the circle is visible.

Returns
  • trueif the circle is visible;falseif it is invisible.

public voidremove()

Removes this circle from the map. After a circle has been removed, the behavior of all its methods is undefined.

public voidsetCenter(LatLng center)

Sets the center using aLatLng.

The center must not benull,as there is no default value.

Parameters
center The geographic center of the circle, specified as aLatLng.
Throws
NullPointerException if center isnull.

public voidsetClickable(boolean clickable)

Sets the clickability of the circle. If the circle is clickable, your app will receive notifications to theGoogleMap.OnCircleClickListener when the user clicks the circle. The event listener is registered through GoogleMap.setOnCircleClickListener(GoogleMap.OnCircleClickListener).

Parameters
clickable New clickability setting for the circle.

public voidsetFillColor(int color)

Sets the fill color.

The fill color is the color inside the circle, in the integer format specified by Color.If TRANSPARENT is used then no fill is drawn.

Parameters
color The color in theColor format.

public voidsetRadius(double radius)

Sets the radius in meters.

The radius must be zero or greater.

Parameters
radius The radius, in meters.
Throws
IllegalArgumentException if radius is negative

public voidsetStrokeColor(int color)

Sets the stroke color.

The stroke color is the color of this circle's outline, in the integer format specified byColor.If TRANSPARENT is used then no outline is drawn.

Parameters
color The stroke color in theColor format.

public voidsetStrokePattern(List<PatternItem> pattern)

Sets the stroke pattern of the circle's outline. The default stroke pattern is solid, represented bynull.

Parameters
pattern the stroke pattern.

public voidsetStrokeWidth(float width)

Sets the stroke width.

The stroke width is the width (in screen pixels) of the circle's outline. It must be zero or greater. If it is zero then no outline is drawn. The default value is 10.

Parameters
width The stroke width, in screen pixels.
Throws
IllegalArgumentException if width is negative

public voidsetTag(Objecttag)

Sets the tag for the circle.

You can use this property to associate an arbitraryObjectwith this circle. For example, theObjectcan contain data about what the circle represents. This is easier than storing a separateMap<Circle, Object>.As another example, you can associate aStringID corresponding to the ID from a data set. Google Maps SDK for Android neither reads nor writes this property. It is your responsibility to callsetTag(null)to clear the tag when you no longer need it, to prevent memory leaks in your app.

Parameters
tag ifnull,the tag is cleared.

public voidsetVisible(boolean visible)

Sets the visibility of the circle.

If this circle is not visible then it will not be drawn. All other state is preserved. Circles are visible by default.

Parameters
visible trueto make this circle visible;falseto make it invisible.

public voidsetZIndex(float zIndex)

Sets the zIndex.

Overlays (such as circles) with higher zIndices are drawn above those with lower indices.

Parameters
zIndex The zIndex value.