Markers with Vector-Based Icons Stay organized with collections Save and categorize content based on your preferences.
AI-generated Key Takeaways
google.maps.Markeris deprecated; it is recommended to transition togoogle.maps.marker.AdvancedMarkerElementfor improved functionality.This example demonstrates creating a custom marker icon using SVG path notation, resulting in a blue, marker-shaped symbol on the map.
The sample code provides implementations in both TypeScript and JavaScript, along with HTML and CSS for styling and map display.
To run the sample locally, Git and Node.js are required, and instructions for cloning and running the sample application are provided.
As of February 21st, 2024 (v3.56), google.maps.Marker is deprecated. We encourage you to transition to the newgoogle.maps.marker.AdvancedMarkerElement class. Advanced markers provide substantial improvements over the legacygoogle.maps.Marker class. The minimum version of the Maps JavaScript API withgoogle.maps.marker.AdvancedMarkerElement is 3.53.2. At this time, google.maps.Marker is not scheduled to be discontinued.
This example uses SVG path notation to add a vector-based symbol as the iconfor a marker. The resulting icon is a marker-shaped symbol with a blue fill andno border.
Read thedocumentation.
TypeScript
// This example uses SVG path notation to add a vector-based symbol// as the icon for a marker. The resulting icon is a marker-shaped// symbol with a blue fill and no border.functioninitMap():void{constcenter=newgoogle.maps.LatLng(-33.712451,150.311823);constmap=newgoogle.maps.Map(document.getElementById("map")asHTMLElement,{zoom:9,center:center,});constsvgMarker={path:"M-1.547 12l6.563-6.609-1.406-1.406-5.156 5.203-2.063-2.109-1.406 1.406zM0 0q2.906 0 4.945 2.039t2.039 4.945q0 1.453-0.727 3.328t-1.758 3.516-2.039 3.070-1.711 2.273l-0.75 0.797q-0.281-0.328-0.75-0.867t-1.688-2.156-2.133-3.141-1.664-3.445-0.75-3.375q0-2.906 2.039-4.945t4.945-2.039z",fillColor:"blue",fillOpacity:0.6,strokeWeight:0,rotation:0,scale:2,anchor:newgoogle.maps.Point(0,20),};newgoogle.maps.Marker({position:map.getCenter(),icon:svgMarker,map:map,});}declareglobal{interfaceWindow{initMap:()=>void;}}window.initMap=initMap;
JavaScript
// This example uses SVG path notation to add a vector-based symbol// as the icon for a marker. The resulting icon is a marker-shaped// symbol with a blue fill and no border.functioninitMap(){constcenter=newgoogle.maps.LatLng(-33.712451,150.311823);constmap=newgoogle.maps.Map(document.getElementById("map"),{zoom:9,center:center,});constsvgMarker={path:"M-1.547 12l6.563-6.609-1.406-1.406-5.156 5.203-2.063-2.109-1.406 1.406zM0 0q2.906 0 4.945 2.039t2.039 4.945q0 1.453-0.727 3.328t-1.758 3.516-2.039 3.070-1.711 2.273l-0.75 0.797q-0.281-0.328-0.75-0.867t-1.688-2.156-2.133-3.141-1.664-3.445-0.75-3.375q0-2.906 2.039-4.945t4.945-2.039z",fillColor:"blue",fillOpacity:0.6,strokeWeight:0,rotation:0,scale:2,anchor:newgoogle.maps.Point(0,20),};newgoogle.maps.Marker({position:map.getCenter(),icon:svgMarker,map:map,});}window.initMap=initMap;
CSS
/* * Always set the map height explicitly to define the size of the div element * that contains the map. */#map{height:100%;}/* * Optional: Makes the sample page fill the window. */html,body{height:100%;margin:0;padding:0;}
HTML
<html> <head> <title>Custom Symbols (Marker)</title> <link rel="stylesheet" type="text/css" href="./style.css" /> <script type="module" src="./index.js"></script> </head> <body> <div></div> <!-- The `defer` attribute causes the script to execute after the full HTML document has been parsed. For non-blocking uses, avoiding race conditions, and consistent behavior across browsers, consider loading using Promises. See https://developers.google.com/maps/documentation/javascript/load-maps-js-api for more information. --> <script src="https://maps.googleapis.com/maps/api/js?key=AIzaSyB41DRUbKWJHPxaFjMAwdrzWzbVKartNGg&callback=initMap&v=weekly" defer ></script> </body></html>
Try Sample
Clone Sample
Git and Node.js are required to run this sample locally. Follow theseinstructions to install Node.js and NPM. The following commands clone, install dependencies and start the sample application.
gitclone-bsample-marker-symbol-customhttps://github.com/googlemaps/js-samples.gitcdjs-samplesnpminpmstart
Other samples can be tried by switching to any branch beginning withsample-SAMPLE_NAME.
gitcheckoutsample-SAMPLE_NAMEnpminpmstart
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.