KML Stay organized with collections Save and categorize content based on your preferences.
KmlLayerclass
google.maps.KmlLayerclass
AKmlLayer adds geographic markup to the map from a KML, KMZ or GeoRSS file that is hosted on a publicly accessible web server. AKmlFeatureData object is provided for each feature when clicked.
This class extendsMVCObject.
Access by callingconst {KmlLayer} = await google.maps.importLibrary("maps").
SeeLibraries in the Maps JavaScript API.
Constructor | |
|---|---|
KmlLayer | KmlLayer([opts])Parameters:
Creates a KmlLayer which renders the contents of the specified KML/KMZ file (https://developers.google.com/kml/documentation/kmlreference) or GeoRSS file (http://www.georss.org). |
Methods | |
|---|---|
getDefaultViewport | getDefaultViewport()Parameters: None Return Value: LatLngBoundsGet the default viewport for the layer being displayed. |
getMap | getMap()Parameters: None Return Value: MapGet the map on which the KML Layer is being rendered. |
getMetadata | getMetadata()Parameters: None Return Value: KmlLayerMetadataGet the metadata associated with this layer, as specified in the layer markup. |
getStatus | getStatus()Parameters: None Return Value: KmlLayerStatusGet the status of the layer, set once the requested document has loaded. |
getUrl | getUrl()Parameters: None Return Value: string URLGets the URL of the KML file being displayed. |
getZIndex | getZIndex()Parameters: None Return Value: number The z-index.Gets the z-index of the KML Layer. |
setMap | setMap(map)Parameters:
Return Value: None Renders the KML Layer on the specified map. If map is set to null, the layer is removed. |
setOptions | setOptions(options)Parameters:
Return Value: None |
setUrl | setUrl(url)Parameters:
Return Value: None Sets the URL of the KML file to display. |
setZIndex | setZIndex(zIndex)Parameters:
Return Value: None Sets the z-index of the KML Layer. |
Inherited:addListener,bindTo,get,notify,set,setValues,unbind,unbindAll | |
Events | |
|---|---|
click | function(kmlClickEvent)Arguments:
This event is fired when a feature in the layer is clicked. |
defaultviewport_changed | function()Arguments: None This event is fired when the KML layers default viewport has changed. |
status_changed | function()Arguments: None This event is fired when the KML layer has finished loading. At this point it is safe to read the status property to determine if the layer loaded successfully. |
KmlLayerOptionsinterface
google.maps.KmlLayerOptionsinterface
This object defines the properties that can be set on aKmlLayer object.
Properties | |
|---|---|
clickableoptional | Type: booleanoptionalDefault: trueIf true, the layer receives mouse events. |
mapoptional | Type: MapoptionalThe map on which to display the layer. |
preserveViewportoptional | Type: booleanoptionalDefault: falseIf this option is set to true or if the map's center and zoom were never set, the input map is centered and zoomed to the bounding box of the contents of the layer. |
screenOverlaysoptional | Type: booleanoptionalDefault: trueWhether to render the screen overlays. |
suppressInfoWindowsoptional | Type: booleanoptionalSuppress the rendering of info windows when layer features are clicked. |
urloptional | Type: stringoptionalThe URL of the KML document to display. |
zIndexoptional | Type: numberoptionalThe z-index of the layer. |
KmlLayerMetadatainterface
google.maps.KmlLayerMetadatainterface
Metadata for a single KML layer, in JSON format.
Properties | |
|---|---|
description | Type: stringThe layer's <description>, extracted from the layer markup. |
hasScreenOverlays | Type: booleanWhether the layer has any screen overlays. |
name | Type: stringThe layer's <name>, extracted from the layer markup. |
snippet | Type: stringThe layer's <Snippet>, extracted from the layer markup |
authoroptional | Type: KmlAuthoroptionalThe layer's <atom:author>, extracted from the layer markup. |
KmlLayerStatusconstants
google.maps.KmlLayerStatusconstants
The status returned byKmlLayer on the completion of loading a document. Specify these by value, or by using the constant's name. For example,'OK' orgoogle.maps.KmlLayerStatus.OK.
Access by callingconst {KmlLayerStatus} = await google.maps.importLibrary("maps").
SeeLibraries in the Maps JavaScript API.
Constants | |
|---|---|
DOCUMENT_NOT_FOUND | The document could not be found. Most likely it is an invalid URL, or the document is not publicly available. |
DOCUMENT_TOO_LARGE | The document exceeds the file size limits of KmlLayer. |
FETCH_ERROR | The document could not be fetched. |
INVALID_DOCUMENT | The document is not a valid KML, KMZ or GeoRSS document. |
INVALID_REQUEST | TheKmlLayer is invalid. |
LIMITS_EXCEEDED | The document exceeds the feature limits of KmlLayer. |
OK | The layer loaded successfully. |
TIMED_OUT | The document could not be loaded within a reasonable amount of time. |
UNKNOWN | The document failed to load for an unknown reason. |
KmlMouseEventinterface
google.maps.KmlMouseEventinterface
The properties of a click event on a KML/KMZ or GeoRSS document.
Properties | |
|---|---|
featureData | Type: KmlFeatureDataA KmlFeatureData object, containing information about the clicked feature. |
latLng | Type: LatLngThe position at which to anchor an infowindow on the clicked feature. |
pixelOffset | Type: SizeThe offset to apply to an infowindow anchored on the clicked feature. |
KmlFeatureDatainterface
google.maps.KmlFeatureDatainterface
Data for a single KML feature in JSON format, returned when a KML feature is clicked. The data contained in this object mirrors that associated with the feature in the KML or GeoRSS markup in which it is declared.
Properties | |
|---|---|
author | Type: KmlAuthorThe feature's <atom:author>, extracted from the layer markup (if specified). |
description | Type: stringThe feature's <description>, extracted from the layer markup. |
id | Type: stringThe feature's <id>, extracted from the layer markup. If no<id> has been specified, a unique ID will be generated for this feature. |
infoWindowHtml | Type: stringThe feature's balloon styled text, if set. |
name | Type: stringThe feature's <name>, extracted from the layer markup. |
snippet | Type: stringThe feature's <Snippet>, extracted from the layer markup. |
KmlAuthorinterface
google.maps.KmlAuthorinterface
Contains details of the author of a KML document or feature.
Properties | |
|---|---|
email | Type: stringThe author's e-mail address, or an empty string if not specified. |
name | Type: stringThe author's name, or an empty string if not specified. |
uri | Type: stringThe author's home page, or an empty string if not specified. |
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-11-21 UTC.