Introducing Places UI Kit: A ready-to-use, low-cost component library that lets you bring the familiar Google Maps UI for Places to any map of your choice. Try it out, andshare your input to help shape the future of GMP!

Data

Dataclass

google.maps.Dataclass

A layer for displaying geospatial data. Points, line-strings and polygons can be displayed.

EveryMap has aData object by default, so most of the time there is no need to construct one. For example:

 var myMap = new google.maps.Map(...);
myMap.data.addGeoJson(...);
myMap.data.setStyle(...);
TheData object is a collection ofFeatures.

This class extendsMVCObject.

Access by callingconst {Data} = await google.maps.importLibrary("maps").
SeeLibraries in the Maps JavaScript API.

Constructor

Data
Data([options])
Parameters: 
Creates an empty collection, with the givenDataOptions.

Methods

add
add([feature])
Parameters: 
Return Value: Data.Feature
Adds a feature to the collection, and returns the added feature.

If the feature has an ID, it will replace any existing feature in the collection with the same ID. If no feature is given, a new feature will be created with null geometry and no properties. IfFeatureOptions are given, a new feature will be created with the specified properties.

Note that the IDs1234 and'1234' are equivalent. Adding a feature with ID1234 will replace a feature with ID'1234', and vice versa.

addGeoJson
addGeoJson(geoJson[, options])
Parameters: 
Return Value: Array<Data.Feature>
Adds GeoJSON features to the collection. Give this method a parsed JSON. The imported features are returned. Throws an exception if the GeoJSON could not be imported.
contains
contains(feature)
Parameters: 
Return Value: boolean
Checks whether the given feature is in the collection.
forEach
forEach(callback)
Parameters: 
Return Value:  None
Repeatedly invokes the given function, passing a feature in the collection to the function on each invocation. The order of iteration through the features is undefined.
getControlPosition
getControlPosition()
Parameters:  None
Return Value: ControlPosition
Returns the position of the drawing controls on the map.
getControls
getControls()
Parameters:  None
Return Value: Array<string>
Returns which drawing modes are available for the user to select, in the order they are displayed. This does not include thenull drawing mode, which is added by default. Possible drawing modes are"Point","LineString" or"Polygon".
getDrawingMode
getDrawingMode()
Parameters:  None
Return Value: string|null
Returns the current drawing mode of the given Data layer. A drawing mode ofnull means that the user can interact with the map as normal, and clicks do not draw anything. Possible drawing modes arenull,"Point","LineString" or"Polygon".
getFeatureById
getFeatureById(id)
Parameters: 
  • idnumber|string
Return Value: Data.Feature|undefined
Returns the feature with the given ID, if it exists in the collection. Otherwise returnsundefined.

Note that the IDs1234 and'1234' are equivalent. Either can be used to look up the same feature.

getMap
getMap()
Parameters:  None
Return Value: Map
Returns the map on which the features are displayed.
getStyle
getStyle()
Parameters:  None
Gets the style for all features in the collection.
loadGeoJson
loadGeoJson(url[, options, callback])
Parameters: 
Return Value:  None
Loads GeoJSON from a URL, and adds the features to the collection.

NOTE: The GeoJSON is fetched using XHR, and may not work cross-domain. If you have issues, we recommend you fetch the GeoJSON using your choice of AJAX library, and then calladdGeoJson().

overrideStyle
overrideStyle(feature, style)
Parameters: 
Return Value:  None
Changes the style of a feature. These changes are applied on top of the style specified bysetStyle(). Style properties set tonull revert to the value specified viasetStyle().
remove
remove(feature)
Parameters: 
Return Value:  None
Removes a feature from the collection.
revertStyle
revertStyle([feature])
Parameters: 
Return Value:  None
Removes the effect of previousoverrideStyle() calls. The style of the given feature reverts to the style specified bysetStyle().

If no feature is given, all features have their style reverted.

setControlPosition
setControlPosition(controlPosition)
Parameters: 
Return Value:  None
Sets the position of the drawing controls on the map.
setControls
setControls(controls)
Parameters: 
Return Value:  None
Sets which drawing modes are available for the user to select, in the order they are displayed. This should not include thenull drawing mode, which is added by default. Ifnull, drawing controls are disabled and not displayed. Possible drawing modes are"Point","LineString" or"Polygon".
setDrawingMode
setDrawingMode(drawingMode)
Parameters: 
  • drawingModestringoptional
Return Value:  None
Sets the current drawing mode of the given Data layer. A drawing mode ofnull means that the user can interact with the map as normal, and clicks do not draw anything. Possible drawing modes arenull,"Point","LineString" or"Polygon".
setMap
setMap(map)
Parameters: 
Return Value:  None
Renders the features on the specified map. If map is set tonull, the features will be removed from the map.
setStyle
setStyle(style)
Return Value:  None
Sets the style for all features in the collection. Styles specified on a per-feature basis viaoverrideStyle() continue to apply.

Pass either an object with the desired style options, or a function that computes the style for each feature. The function will be called every time a feature's properties are updated.

toGeoJson
toGeoJson(callback)
Parameters: 
  • callbackfunction(Object): void
Return Value:  None
Exports the features in the collection to a GeoJSON object.
Inherited:addListener,bindTo,get,notify,set,setValues,unbind,unbindAll

Events

addfeature
function(event)
Arguments: 
This event is fired when a feature is added to the collection.
click
function(event)
Arguments: 
This event is fired for a click on the geometry.
contextmenu
function(event)
Arguments: 
This event is fired when the DOM contextmenu event is fired on the geometry.
dblclick
function(event)
Arguments: 
This event is fired for a double click on the geometry.
mousedown
function(event)
Arguments: 
This event is fired for a mousedown on the geometry.
mouseout
function(event)
Arguments: 
This event is fired when the mouse leaves the area of the geometry.
mouseover
function(event)
Arguments: 
This event is fired when the mouse enters the area of the geometry.
mouseup
function(event)
Arguments: 
This event is fired for a mouseup on the geometry.
removefeature
function(event)
Arguments: 
This event is fired when a feature is removed from the collection.
removeproperty
function(event)
Arguments: 
This event is fired when a feature's property is removed.
setgeometry
function(event)
Arguments: 
This event is fired when a feature's geometry is set.
setproperty
function(event)
Arguments: 
This event is fired when a feature's property is set.
rightclick

Deprecated: Use theData.contextmenu event instead in order to support usage patterns like control-click on macOS.

function(event)
Arguments: 
This event is fired for a rightclick on the geometry.

Data.DataOptionsinterface

google.maps.Data.DataOptionsinterface

DataOptions object used to define the properties that a developer can set on aData object.

Properties

map
Type: Map
Map on which to display the features in the collection.
controlPositionoptional
Type: ControlPositionoptional
The position of the drawing controls on the map.
controlsoptional
Type: Array<string>optional
Default:null
Describes which drawing modes are available for the user to select, in the order they are displayed. This should not include thenull drawing mode, which is added by default. Ifnull, drawing controls are disabled and not displayed. Possible drawing modes are"Point","LineString" or"Polygon".
drawingModeoptional
Type: stringoptional
Default:null
The current drawing mode of the given Data layer. A drawing mode ofnull means that the user can interact with the map as normal, and clicks do not draw anything. Possible drawing modes arenull,"Point","LineString" or"Polygon".
featureFactoryoptional
Type: function(Data.Geometry):Data.Featureoptional
When drawing is enabled and a user draws a Geometry (a Point, Line String or Polygon), this function is called with that Geometry and should return a Feature that is to be added to the Data layer. If a featureFactory is not supplied, a Feature with no id and no properties will be created from that Geometry instead. Defaults tonull.
styleoptional
Style for all features in the collection. For more details, see thesetStyle() method above.

Data.GeoJsonOptionsinterface

google.maps.Data.GeoJsonOptionsinterface

Optional parameters for importing GeoJSON.

Properties

idPropertyNameoptional
Type: stringoptional
The name of the Feature property to use as the feature ID. If not specified, the GeoJSON Feature id will be used.

Data.StyleOptionsinterface

google.maps.Data.StyleOptionsinterface

These options specify the way a Feature should appear when displayed on a map.

Properties

animationoptional
Type: Animationoptional
The animation to play when marker is added to a map. Only applies to point geometries.
clickableoptional
Type: booleanoptional
Default:true
Iftrue, the marker receives mouse and touch events.
cursoroptional
Type: stringoptional
Mouse cursor to show on hover. Only applies to point geometries.
draggableoptional
Type: booleanoptional
Default:false
Iftrue, the object can be dragged across the map and the underlying feature will have its geometry updated.
editableoptional
Type: booleanoptional
Default:false
Iftrue, the object can be edited by dragging control points and the underlying feature will have its geometry updated. Only applies to LineString and Polygon geometries.
fillColoroptional
Type: stringoptional
The fill color. All CSS3 colors are supported except for extended named colors. Only applies to polygon geometries.
fillOpacityoptional
Type: numberoptional
The fill opacity between 0.0 and 1.0. Only applies to polygon geometries.
iconoptional
Type: string|Icon|Symboloptional
Icon for the foreground. If a string is provided, it is treated as though it were anIcon with the string asurl. Only applies to point geometries.
iconsoptional
Type: Array<IconSequence>optional
The icons to be rendered along a polyline. Only applies to line geometries.
labeloptional
Type: string|MarkerLabeloptional
Adds a label to the marker. The label can either be a string, or aMarkerLabel object. Only applies to point geometries.
opacityoptional
Type: numberoptional
The marker's opacity between 0.0 and 1.0. Only applies to point geometries.
shapeoptional
Type: MarkerShapeoptional
Defines the image map used for hit detection. Only applies to point geometries.
strokeColoroptional
Type: stringoptional
The stroke color. All CSS3 colors are supported except for extended named colors. Only applies to line and polygon geometries.
strokeOpacityoptional
Type: numberoptional
The stroke opacity between 0.0 and 1.0. Only applies to line and polygon geometries.
strokeWeightoptional
Type: numberoptional
The stroke width in pixels. Only applies to line and polygon geometries.
titleoptional
Type: stringoptional
Rollover text. Only applies to point geometries.
visibleoptional
Type: booleanoptional
Default:true
Whether the feature is visible.
zIndexoptional
Type: numberoptional
All features are displayed on the map in order of their zIndex, with higher values displaying in front of features with lower values. Markers are always displayed in front of line-strings and polygons.

Data.StylingFunctiontypedef

google.maps.Data.StylingFunctiontypedef

A function that computes the appearance of a feature.

TheData.setStyle() method can accept a styling function. Use this when features should appear differently depending on their properties. You can find more information about styling features in thedeveloper's guide.

function(Data.Feature):Data.StyleOptions

Data.Featureclass

google.maps.Data.Featureclass

A feature has a geometry, an id, and a set of properties.

Access by callingconst {Data} = await google.maps.importLibrary("maps").
SeeLibraries in the Maps JavaScript API.

Constructor

Data.Feature
Data.Feature([options])
Parameters: 
Constructs a Feature with the given options.

Methods

forEachProperty
forEachProperty(callback)
Parameters: 
  • callbackfunction(*, string): void
Return Value:  None
Repeatedly invokes the given function, passing a property value and name on each invocation. The order of iteration through the properties is undefined.
getGeometry
getGeometry()
Parameters:  None
Return Value: Data.Geometry
Returns the feature's geometry.
getId
getId()
Parameters:  None
Return Value: number|string|undefined
Returns the feature ID.
getProperty
getProperty(name)
Parameters: 
  • namestring
Return Value: *
Returns the value of the requested property, orundefined if the property does not exist.
removeProperty
removeProperty(name)
Parameters: 
  • namestring
Return Value:  None
Removes the property with the given name.
setGeometry
setGeometry(newGeometry)
Parameters: 
Return Value:  None
Sets the feature's geometry.
setProperty
setProperty(name, newValue)
Parameters: 
  • namestring
  • newValue*
Return Value:  None
Sets the value of the specified property. IfnewValue isundefined this is equivalent to callingremoveProperty.
toGeoJson
toGeoJson(callback)
Parameters: 
  • callbackfunction(Object): void
Return Value:  None
Exports the feature to a GeoJSON object.

Events

removeproperty
function(event)
Arguments: 
This event is triggered when a feature's property is removed.
setgeometry
function(event)
Arguments: 
This event is triggered when a feature's geometry is set.
setproperty
function(event)
Arguments: 
This event is triggered when a feature's property is set.

Data.FeatureOptionsinterface

google.maps.Data.FeatureOptionsinterface

Optional parameters for creatingData.Feature objects.

Properties

geometryoptional
The feature geometry. If none is specified when a feature is constructed, the feature's geometry will benull. If aLatLng object orLatLngLiteral is given, this will be converted to aData.Point geometry.
idoptional
Type: number|stringoptional
Feature ID is optional. If provided, it can be used to look up the feature in aData object using thegetFeatureById() method. Note that a feature's ID cannot be subsequently changed.
propertiesoptional
Type: Objectoptional
The feature properties. This is an arbitrary mapping of property names to values.

Data.Geometryinterface

google.maps.Data.Geometryinterface

A superclass for the various geometry objects.

Methods

forEachLatLng
forEachLatLng(callback)
Parameters: 
  • callbackfunction(LatLng): void
Return Value:  None
Repeatedly invokes the given function, passing a point from the geometry to the function on each invocation.
getType
getType()
Parameters:  None
Return Value: string
Returns the type of the geometry object. Possibilities are"Point","MultiPoint","LineString","MultiLineString","LinearRing","Polygon","MultiPolygon", or"GeometryCollection".

Data.Pointclass

google.maps.Data.Pointclass

A Point geometry contains a singleLatLng.

This class implementsData.Geometry.

Access by callingconst {Data} = await google.maps.importLibrary("maps").
SeeLibraries in the Maps JavaScript API.

Constructor

Data.Point
Data.Point(latLng)
Parameters: 
Constructs aData.Point from the givenLatLng orLatLngLiteral.

Methods

forEachLatLng
forEachLatLng(callback)
Parameters: 
  • callbackfunction(LatLng): void
Return Value:  None
get
get()
Parameters:  None
Return Value: LatLng
Returns the containedLatLng.
getType
getType()
Parameters:  None
Return Value: string
Returns the string"Point".

Data.MultiPointclass

google.maps.Data.MultiPointclass

A MultiPoint geometry contains a number ofLatLngs.

This class implementsData.Geometry.

Access by callingconst {Data} = await google.maps.importLibrary("maps").
SeeLibraries in the Maps JavaScript API.

Constructor

Data.MultiPoint
Data.MultiPoint(elements)
Parameters: 
Constructs aData.MultiPoint from the givenLatLngs orLatLngLiterals.

Methods

forEachLatLng
forEachLatLng(callback)
Parameters: 
  • callbackfunction(LatLng): void
Return Value:  None
getArray
getArray()
Parameters:  None
Return Value: Array<LatLng>
Returns an array of the containedLatLngs. A new array is returned each timegetArray() is called.
getAt
getAt(n)
Parameters: 
  • nnumber
Return Value: LatLng
Returns then-th containedLatLng.
getLength
getLength()
Parameters:  None
Return Value: number
Returns the number of containedLatLngs.
getType
getType()
Parameters:  None
Return Value: string
Returns the string"MultiPoint".

Data.LineStringclass

google.maps.Data.LineStringclass

A LineString geometry contains a number ofLatLngs.

This class implementsData.Geometry.

Access by callingconst {Data} = await google.maps.importLibrary("maps").
SeeLibraries in the Maps JavaScript API.

Constructor

Data.LineString
Data.LineString(elements)
Parameters: 
Constructs aData.LineString from the givenLatLngs orLatLngLiterals.

Methods

forEachLatLng
forEachLatLng(callback)
Parameters: 
  • callbackfunction(LatLng): void
Return Value:  None
getArray
getArray()
Parameters:  None
Return Value: Array<LatLng>
Returns an array of the containedLatLngs. A new array is returned each timegetArray() is called.
getAt
getAt(n)
Parameters: 
  • nnumber
Return Value: LatLng
Returns then-th containedLatLng.
getLength
getLength()
Parameters:  None
Return Value: number
Returns the number of containedLatLngs.
getType
getType()
Parameters:  None
Return Value: string
Returns the string"LineString".

Data.MultiLineStringclass

google.maps.Data.MultiLineStringclass

A MultiLineString geometry contains a number ofLineStrings.

This class implementsData.Geometry.

Access by callingconst {Data} = await google.maps.importLibrary("maps").
SeeLibraries in the Maps JavaScript API.

Constructor

Data.MultiLineString
Data.MultiLineString(elements)
Parameters: 
Constructs aData.MultiLineString from the givenData.LineStrings or arrays of positions.

Methods

forEachLatLng
forEachLatLng(callback)
Parameters: 
  • callbackfunction(LatLng): void
Return Value:  None
getArray
getArray()
Parameters:  None
Return Value: Array<Data.LineString>
Returns an array of the containedData.LineStrings. A new array is returned each timegetArray() is called.
getAt
getAt(n)
Parameters: 
  • nnumber
Return Value: Data.LineString
Returns then-th containedData.LineString.
getLength
getLength()
Parameters:  None
Return Value: number
Returns the number of containedData.LineStrings.
getType
getType()
Parameters:  None
Return Value: string
Returns the string"MultiLineString".

Data.LinearRingclass

google.maps.Data.LinearRingclass

A LinearRing geometry contains a number ofLatLngs, representing a closed LineString. There is no need to make the firstLatLng equal to the lastLatLng. The LinearRing is closed implicitly.

This class implementsData.Geometry.

Access by callingconst {Data} = await google.maps.importLibrary("maps").
SeeLibraries in the Maps JavaScript API.

Constructor

Data.LinearRing
Data.LinearRing(elements)
Parameters: 
Constructs aData.LinearRing from the givenLatLngs orLatLngLiterals.

Methods

forEachLatLng
forEachLatLng(callback)
Parameters: 
  • callbackfunction(LatLng): void
Return Value:  None
getArray
getArray()
Parameters:  None
Return Value: Array<LatLng>
Returns an array of the containedLatLngs. A new array is returned each timegetArray() is called.
getAt
getAt(n)
Parameters: 
  • nnumber
Return Value: LatLng
Returns then-th containedLatLng.
getLength
getLength()
Parameters:  None
Return Value: number
Returns the number of containedLatLngs.
getType
getType()
Parameters:  None
Return Value: string
Returns the string"LinearRing".

Data.Polygonclass

google.maps.Data.Polygonclass

A Polygon geometry contains a number ofData.LinearRings. The first linear-ring must be the polygon exterior boundary and subsequent linear-rings must be interior boundaries, also known as holes. See thesample polygon with a hole.

This class implementsData.Geometry.

Access by callingconst {Data} = await google.maps.importLibrary("maps").
SeeLibraries in the Maps JavaScript API.

Constructor

Data.Polygon
Data.Polygon(elements)
Parameters: 
Constructs aData.Polygon from the givenData.LinearRings or arrays of positions.

Methods

forEachLatLng
forEachLatLng(callback)
Parameters: 
  • callbackfunction(LatLng): void
Return Value:  None
getArray
getArray()
Parameters:  None
Return Value: Array<Data.LinearRing>
Returns an array of the containedData.LinearRings. A new array is returned each timegetArray() is called.
getAt
getAt(n)
Parameters: 
  • nnumber
Return Value: Data.LinearRing
Returns then-th containedData.LinearRing.
getLength
getLength()
Parameters:  None
Return Value: number
Returns the number of containedData.LinearRings.
getType
getType()
Parameters:  None
Return Value: string
Returns the string"Polygon".

Data.MultiPolygonclass

google.maps.Data.MultiPolygonclass

A MultiPolygon geometry contains a number ofData.Polygons.

This class implementsData.Geometry.

Access by callingconst {Data} = await google.maps.importLibrary("maps").
SeeLibraries in the Maps JavaScript API.

Constructor

Data.MultiPolygon
Data.MultiPolygon(elements)
Constructs aData.MultiPolygon from the givenData.Polygons or arrays of positions.

Methods

forEachLatLng
forEachLatLng(callback)
Parameters: 
  • callbackfunction(LatLng): void
Return Value:  None
getArray
getArray()
Parameters:  None
Return Value: Array<Data.Polygon>
Returns an array of the containedData.Polygons. A new array is returned each timegetArray() is called.
getAt
getAt(n)
Parameters: 
  • nnumber
Return Value: Data.Polygon
Returns then-th containedData.Polygon.
getLength
getLength()
Parameters:  None
Return Value: number
Returns the number of containedData.Polygons.
getType
getType()
Parameters:  None
Return Value: string
Returns the string"MultiPolygon".

Data.GeometryCollectionclass

google.maps.Data.GeometryCollectionclass

A GeometryCollection contains a number of geometry objects. AnyLatLng orLatLngLiteral objects are automatically converted toData.Point geometry objects.

This class implementsData.Geometry.

Access by callingconst {Data} = await google.maps.importLibrary("maps").
SeeLibraries in the Maps JavaScript API.

Constructor

Data.GeometryCollection
Data.GeometryCollection(elements)
Parameters: 
Constructs aData.GeometryCollection from the given geometry objects orLatLngs.

Methods

forEachLatLng
forEachLatLng(callback)
Parameters: 
  • callbackfunction(LatLng): void
Return Value:  None
getArray
getArray()
Parameters:  None
Return Value: Array<Data.Geometry>
Returns an array of the contained geometry objects. A new array is returned each timegetArray() is called.
getAt
getAt(n)
Parameters: 
  • nnumber
Return Value: Data.Geometry
Returns then-th contained geometry object.
getLength
getLength()
Parameters:  None
Return Value: number
Returns the number of contained geometry objects.
getType
getType()
Parameters:  None
Return Value: string
Returns the string"GeometryCollection".

Data.MouseEventinterface

google.maps.Data.MouseEventinterface

This object is passed to mouse event handlers on aData object.

This interface extendsMapMouseEvent.

Properties

feature
The feature which generated the mouse event.
Inherited:domEvent,latLng

Methods

Inherited:stop

Data.AddFeatureEventinterface

google.maps.Data.AddFeatureEventinterface

The properties of aaddfeature event.

Properties

feature
The feature that was added to theFeatureCollection.

Data.RemoveFeatureEventinterface

google.maps.Data.RemoveFeatureEventinterface

The properties of aremovefeature event.

Properties

feature
The feature that was removed from theFeatureCollection.

Data.SetGeometryEventinterface

google.maps.Data.SetGeometryEventinterface

The properties of asetgeometry event.

Properties

feature
The feature whose geometry was set.
newGeometryoptional
Type: Data.Geometryoptional
The new feature geometry.
oldGeometryoptional
Type: Data.Geometryoptional
The previous feature geometry.

Data.SetPropertyEventinterface

google.maps.Data.SetPropertyEventinterface

The properties of asetproperty event.

Properties

feature
The feature whose property was set.
name
Type: string
The property name.
newValue
Type: *
The new value.
oldValue
Type: *
The previous value. Will beundefined if the property was added.

Data.RemovePropertyEventinterface

google.maps.Data.RemovePropertyEventinterface

The properties of aremoveproperty event.

Properties

feature
The feature whose property was removed.
name
Type: string
The property name.
oldValue
Type: *
The previous value.

Except as otherwise noted, the content of this page is licensed under theCreative Commons Attribution 4.0 License, and code samples are licensed under theApache 2.0 License. For details, see theGoogle Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates.

Last updated 2025-07-18 UTC.