Skip to main content

Markers identify locations on the map. By default, they use a standard icon, though you can set a custom icon. Markers are designed to be interactive and are often used within event listeners to bring up info windows.

Markers (instances of google.maps.Marker) identify locations on the map. By default, they use a standard icon, though you can set a custom icon within the marker's constructor or by calling setIcon() on the marker. Markers are designed to be interactive. By default, they receive click events, which are often used to define event listeners that display an InfoWindow.

The Google Maps JavaScript API v3 Developer's Guide includes a section on Overlays (markers are a special type of overlay), which are objects that you add to the map to designate points, lines, areas, or collections of objects. The Developer's Guide also includes an introductory section on Markers, which are used to identify a specific single point on the map; there is also an example that shows the code used to add a Marker to the map.

The google.maps.Marker constructor takes a single MarkerOptions JavaScript object literal specifying the initial properties of the marker. The following fields are particularly important and commonly set when constructing your marker:

  • position (required) specifies a google.maps.LatLng identifying the initial location of the marker.
  • map (optional) specifies the google.maps.Map object on which to place the marker.

Note that within the Marker constructor, you should specify the map on which to add the marker. If you do not specify this argument, the marker is created but is not attached (or displayed) on the map. You may add the marker later by calling the marker's setMap() function. To remove a marker, call the setMap() function passing null as the argument.

The Google Maps JavaScript API v3 API Reference includes a number of entries that are interesting to developers that are working with markers:

Also of interest to Google Maps developers that use markers, the Map Icon Collection showcases hundreds of free marker icons for Google Maps that are available for download.