Markers with Vector-Based Icons

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.

Read the documentation .

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. 
 function 
  
 initMap 
 () 
 : 
  
 void 
  
 { 
  
 const 
  
 center 
  
 = 
  
 new 
  
 google 
 . 
 maps 
 . 
 LatLng 
 ( 
 - 
 33.712451 
 , 
  
 150.311823 
 ); 
  
 const 
  
 map 
  
 = 
  
 new 
  
 google 
 . 
 maps 
 . 
 Map 
 ( 
  
 document 
 . 
 getElementById 
 ( 
 "map" 
 ) 
  
 as 
  
 HTMLElement 
 , 
  
 { 
  
 zoom 
 : 
  
 9 
 , 
  
 center 
 : 
  
 center 
 , 
  
 } 
  
 ); 
  
 const 
  
 svgMarker 
  
 = 
  
 { 
  
 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 
 : 
  
 new 
  
 google 
 . 
 maps 
 . 
 Point 
 ( 
 0 
 , 
  
 20 
 ), 
  
 }; 
  
 new 
  
 google 
 . 
 maps 
 . 
 Marker 
 ({ 
  
 position 
 : 
  
 map.getCenter 
 (), 
  
 icon 
 : 
  
 svgMarker 
 , 
  
 map 
 : 
  
 map 
 , 
  
 }); 
 } 
 declare 
  
 global 
  
 { 
  
 interface 
  
 Window 
  
 { 
  
 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. 
 function 
  
 initMap 
 () 
  
 { 
  
 const 
  
 center 
  
 = 
  
 new 
  
 google 
 . 
 maps 
 . 
 LatLng 
 ( 
 - 
 33.712451 
 , 
  
 150.311823 
 ); 
  
 const 
  
 map 
  
 = 
  
 new 
  
 google 
 . 
 maps 
 . 
 Map 
 ( 
 document 
 . 
 getElementById 
 ( 
 "map" 
 ), 
  
 { 
  
 zoom 
 : 
  
 9 
 , 
  
 center 
 : 
  
 center 
 , 
  
 }); 
  
 const 
  
 svgMarker 
  
 = 
  
 { 
  
 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 
 : 
  
 new 
  
 google 
 . 
 maps 
 . 
 Point 
 ( 
 0 
 , 
  
 20 
 ), 
  
 }; 
  
 new 
  
 google 
 . 
 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 id="map"></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 these instructions to install Node.js and NPM. The following commands clone, install dependencies and start the sample application.

  
  git 
  
 clone 
  
 - 
 b 
  
 sample 
 - 
 marker 
 - 
 symbol 
 - 
 custom 
  
 https 
 : 
 //github.com/googlemaps/js-samples.git 
 
  
  cd 
  
 js 
 - 
 samples 
 
  
  npm 
  
 i 
 
  
  npm 
  
 start 
 

Other samples can be tried by switching to any branch beginning with sample- SAMPLE_NAME .

  
  git 
  
 checkout 
  
 sample 
 - 
  SAMPLE_NAME 
 
 
  
  npm 
  
 i 
 
  
  npm 
  
 start 
 
Design a Mobile Site
View Site in Mobile | Classic
Share by: