A circle on the earth's surface (spherical cap).
A circle has the following properties.
- Center
- The center of the Circle is specified as a
LatLng
. - 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 by
Color
. The default value is black (0xff000000
). - Stroke pattern
- Solid (default, represented by
null
) 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 by
Color
. The default value is transparent (0x00000000
). - Z-Index
- The order in which this tile overlay is drawn with respect to other overlays (including
GroundOverlay
s,TileOverlay
s,Polyline
s, andPolygon
s but notMarker
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 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
- An
Object
associated with the circle. For example, theObject
can contain data about what the circle represents. This is easier than storing a separateMap<Circle, Object>
. As another example, you can associate aString
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 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 the Shapes developer guide.
Public Method Summary
LatLng | |
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 | |
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 | |
void |
setStrokeWidth(float width)
Sets the stroke width.
|
void |
setTag(Object tag)
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
public LatLng getCenter ()
public int getFillColor ()
Returns the fill color of this Circle.
Returns
- The fill color of the circle in ARGB format.
public String getId ()
Gets this circle's id. The id will be unique amongst all Circles on a map.
public double getRadius ()
Returns the circle's radius, in meters.
Returns
- The radius in meters.
public int getStrokeColor ()
Returns the stroke color.
Returns
- The color of the circle in ARGB format.
public List<PatternItem> getStrokePattern ()
Returns the stroke pattern of this circle's outline.
Returns
- the stroke pattern.
public float getStrokeWidth ()
Returns the stroke width.
Returns
- The width in screen pixels.
public Object getTag ()
Gets the tag for the circle.
Returns
- the tag if a tag was set with
setTag
;null
if no tag has been set.
public float getZIndex ()
Returns the zIndex.
Returns
- The zIndex of this circle.
public boolean isClickable ()
Gets the clickability of the circle. If the circle is clickable, your app will receive
notifications to the GoogleMap.OnCircleClickListener
when the user clicks the circle.
The event listener is registered through setOnCircleClickListener(GoogleMap.OnCircleClickListener)
.
Returns
true
if the circle is clickable;false
if it is not clickable.
public boolean isVisible ()
Checks whether the circle is visible.
Returns
true
if the circle is visible;false
if it is invisible.
public void remove ()
Removes this circle from the map. After a circle has been removed, the behavior of all its methods is undefined.
public void setCenter (LatLng center)
public void setClickable (boolean clickable)
Sets the clickability of the circle. If the circle is clickable, your app will receive
notifications to the GoogleMap.OnCircleClickListener
when the user clicks the circle.
The event listener is registered through setOnCircleClickListener(GoogleMap.OnCircleClickListener)
.
Parameters
clickable | New clickability setting for the circle. |
---|
public void setFillColor (int color)
public void setRadius (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 void setStrokeColor (int color)
public void setStrokePattern (List<PatternItem> pattern)
Sets the stroke pattern of the circle's outline. The default stroke pattern is solid,
represented by null
.
Parameters
pattern | the stroke pattern. |
---|
public void setStrokeWidth (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 void setTag (Object tag)
Sets the tag for the circle.
You can use this property to associate an arbitrary Object
with this circle. For
example, the Object
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
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 void setVisible (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 | true to make this circle visible; false to make it invisible.
|
---|
public void setZIndex (float zIndex)
Sets the zIndex.
Overlays (such as circles) with higher zIndices are drawn above those with lower indices.
Parameters
zIndex | The zIndex value. |
---|