constparser=newDOMParser();asyncfunctioninitMap(){// Request needed libraries.const{Map}=awaitgoogle.maps.importLibrary("maps")asgoogle.maps.MapsLibrary;const{AdvancedMarkerElement,PinElement}=awaitgoogle.maps.importLibrary("marker")asgoogle.maps.MarkerLibrary;constmap=newMap(document.getElementById('map')asHTMLElement,{center:{lat:37.419,lng:-122.02},zoom:14,mapId:'4504f8b37365c3d0',});// Each PinElement is paired with a MarkerView to demonstrate setting each parameter.// Default marker with title text (no PinElement).constmarkerViewWithText=newAdvancedMarkerElement({map,position:{lat:37.419,lng:-122.03},title:'Title text for the marker at lat: 37.419, lng: -122.03',});// Adjust the scale.constpinScaled=newPinElement({scale:1.5,});constmarkerViewScaled=newAdvancedMarkerElement({map,position:{lat:37.419,lng:-122.02},content:pinScaled.element,});// Change the background color.constpinBackground=newPinElement({background:'#FBBC04',});constmarkerViewBackground=newAdvancedMarkerElement({map,position:{lat:37.419,lng:-122.01},content:pinBackground.element,});// Change the border color.constpinBorder=newPinElement({borderColor:'#137333',});constmarkerViewBorder=newAdvancedMarkerElement({map,position:{lat:37.415,lng:-122.035},content:pinBorder.element,});// Change the glyph color.constpinGlyph=newPinElement({glyphColor:'white',});constmarkerViewGlyph=newAdvancedMarkerElement({map,position:{lat:37.415,lng:-122.025},content:pinGlyph.element,});constpinTextGlyph=newPinElement({glyph:'T',glyphColor:'white',});constmarkerViewGlyphText=newAdvancedMarkerElement({map,position:{lat:37.415,lng:-122.015},content:pinTextGlyph.element,});// Hide the glyph.constpinNoGlyph=newPinElement({glyph:'',});constmarkerViewNoGlyph=newAdvancedMarkerElement({map,position:{lat:37.415,lng:-122.005},content:pinNoGlyph.element,});}initMap();
constparser=newDOMParser();asyncfunctioninitMap(){// Request needed libraries.const{Map}=awaitgoogle.maps.importLibrary("maps");const{AdvancedMarkerElement,PinElement}=awaitgoogle.maps.importLibrary("marker");constmap=newMap(document.getElementById('map'),{center:{lat:37.419,lng:-122.02},zoom:14,mapId:'4504f8b37365c3d0',});// Each PinElement is paired with a MarkerView to demonstrate setting each parameter.// Default marker with title text (no PinElement).constmarkerViewWithText=newAdvancedMarkerElement({map,position:{lat:37.419,lng:-122.03},title:'Title text for the marker at lat: 37.419, lng: -122.03',});// Adjust the scale.constpinScaled=newPinElement({scale:1.5,});constmarkerViewScaled=newAdvancedMarkerElement({map,position:{lat:37.419,lng:-122.02},content:pinScaled.element,});// Change the background color.constpinBackground=newPinElement({background:'#FBBC04',});constmarkerViewBackground=newAdvancedMarkerElement({map,position:{lat:37.419,lng:-122.01},content:pinBackground.element,});// Change the border color.constpinBorder=newPinElement({borderColor:'#137333',});constmarkerViewBorder=newAdvancedMarkerElement({map,position:{lat:37.415,lng:-122.035},content:pinBorder.element,});// Change the glyph color.constpinGlyph=newPinElement({glyphColor:'white',});constmarkerViewGlyph=newAdvancedMarkerElement({map,position:{lat:37.415,lng:-122.025},content:pinGlyph.element,});constpinTextGlyph=newPinElement({glyph:'T',glyphColor:'white',});constmarkerViewGlyphText=newAdvancedMarkerElement({map,position:{lat:37.415,lng:-122.015},content:pinTextGlyph.element,});// Hide the glyph.constpinNoGlyph=newPinElement({glyph:'',});constmarkerViewNoGlyph=newAdvancedMarkerElement({map,position:{lat:37.415,lng:-122.005},content:pinNoGlyph.element,});}initMap();
/* * 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;}
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.
[null,null,["Last updated 2025-08-28 UTC."],[[["\u003cp\u003eThis example demonstrates how to customize Google Maps markers using the Advanced Markers and PinElement classes.\u003c/p\u003e\n"],["\u003cp\u003eYou can add title text, scale markers, and change the color of the background, border, and glyph.\u003c/p\u003e\n"],["\u003cp\u003eIt also shows how to hide the glyph for a cleaner look, providing flexibility in marker design.\u003c/p\u003e\n"],["\u003cp\u003eThe provided code snippets in TypeScript, JavaScript, CSS, and HTML offer a comprehensive implementation guide.\u003c/p\u003e\n"],["\u003cp\u003eTo run the sample locally, you need Git and Node.js installed, then follow the cloning and installation instructions.\u003c/p\u003e\n"]]],[],null,["This example shows how to customize markers in the following ways:\n\n- Add title text\n- Scale the marker\n- Change the background color\n- Change the border color\n- Change the glyph color\n- Hide the glyph\n\nRead the\n[documentation](/maps/documentation/javascript/advanced-markers/basic-customization). \n\nTypeScript \n\n```typescript\nconst parser = new DOMParser();\n\nasync function initMap() {\n // Request needed libraries.\n const { Map } = await google.maps.importLibrary(\"maps\") as google.maps.MapsLibrary;\n const { AdvancedMarkerElement, PinElement } = await google.maps.importLibrary(\"marker\") as google.maps.MarkerLibrary;\n\n const map = new Map(document.getElementById('map') as HTMLElement, {\n center: { lat: 37.419, lng: -122.02 },\n zoom: 14,\n mapId: '4504f8b37365c3d0',\n });\n\n // Each PinElement is paired with a MarkerView to demonstrate setting each parameter.\n\n // Default marker with title text (no PinElement).\n const markerViewWithText = new AdvancedMarkerElement({\n map,\n position: { lat: 37.419, lng: -122.03 },\n title: 'Title text for the marker at lat: 37.419, lng: -122.03',\n });\n\n // Adjust the scale.\n const pinScaled = new PinElement({\n scale: 1.5,\n });\n const markerViewScaled = new AdvancedMarkerElement({\n map,\n position: { lat: 37.419, lng: -122.02 },\n content: pinScaled.element,\n });\n\n // Change the background color.\n const pinBackground = new PinElement({\n background: '#FBBC04',\n });\n const markerViewBackground = new AdvancedMarkerElement({\n map,\n position: { lat: 37.419, lng: -122.01 },\n content: pinBackground.element,\n });\n\n // Change the border color.\n const pinBorder = new PinElement({\n borderColor: '#137333',\n });\n const markerViewBorder = new AdvancedMarkerElement({\n map,\n position: { lat: 37.415, lng: -122.035 },\n content: pinBorder.element,\n });\n\n // Change the glyph color.\n const pinGlyph = new PinElement({\n glyphColor: 'white',\n });\n const markerViewGlyph = new AdvancedMarkerElement({\n map,\n position: { lat: 37.415, lng: -122.025 },\n content: pinGlyph.element,\n });\n\n const pinTextGlyph = new PinElement({\n glyph: 'T',\n glyphColor: 'white',\n });\n const markerViewGlyphText = new AdvancedMarkerElement({\n map,\n position: { lat: 37.415, lng: -122.015 },\n content: pinTextGlyph.element,\n });\n\n // Hide the glyph.\n const pinNoGlyph = new PinElement({\n glyph: '',\n });\n const markerViewNoGlyph = new AdvancedMarkerElement({\n map,\n position: { lat: 37.415, lng: -122.005 },\n content: pinNoGlyph.element,\n });\n\n}\n\ninitMap();https://github.com/googlemaps-samples/js-api-samples/blob/5f4e6decfaf59cd69918bbf4e6338de03a63a5ba/samples/advanced-markers-basic-style/index.ts#L8-L106\n```\n| **Note:** Read the [guide](/maps/documentation/javascript/using-typescript) on using TypeScript and Google Maps.\n\nJavaScript \n\n```javascript\nconst parser = new DOMParser();\nasync function initMap() {\n // Request needed libraries.\n const { Map } = await google.maps.importLibrary(\"maps\");\n const { AdvancedMarkerElement, PinElement } = await google.maps.importLibrary(\"marker\");\n const map = new Map(document.getElementById('map'), {\n center: { lat: 37.419, lng: -122.02 },\n zoom: 14,\n mapId: '4504f8b37365c3d0',\n });\n // Each PinElement is paired with a MarkerView to demonstrate setting each parameter.\n // Default marker with title text (no PinElement).\n const markerViewWithText = new AdvancedMarkerElement({\n map,\n position: { lat: 37.419, lng: -122.03 },\n title: 'Title text for the marker at lat: 37.419, lng: -122.03',\n });\n // Adjust the scale.\n const pinScaled = new PinElement({\n scale: 1.5,\n });\n const markerViewScaled = new AdvancedMarkerElement({\n map,\n position: { lat: 37.419, lng: -122.02 },\n content: pinScaled.element,\n });\n // Change the background color.\n const pinBackground = new PinElement({\n background: '#FBBC04',\n });\n const markerViewBackground = new AdvancedMarkerElement({\n map,\n position: { lat: 37.419, lng: -122.01 },\n content: pinBackground.element,\n });\n // Change the border color.\n const pinBorder = new PinElement({\n borderColor: '#137333',\n });\n const markerViewBorder = new AdvancedMarkerElement({\n map,\n position: { lat: 37.415, lng: -122.035 },\n content: pinBorder.element,\n });\n // Change the glyph color.\n const pinGlyph = new PinElement({\n glyphColor: 'white',\n });\n const markerViewGlyph = new AdvancedMarkerElement({\n map,\n position: { lat: 37.415, lng: -122.025 },\n content: pinGlyph.element,\n });\n const pinTextGlyph = new PinElement({\n glyph: 'T',\n glyphColor: 'white',\n });\n const markerViewGlyphText = new AdvancedMarkerElement({\n map,\n position: { lat: 37.415, lng: -122.015 },\n content: pinTextGlyph.element,\n });\n // Hide the glyph.\n const pinNoGlyph = new PinElement({\n glyph: '',\n });\n const markerViewNoGlyph = new AdvancedMarkerElement({\n map,\n position: { lat: 37.415, lng: -122.005 },\n content: pinNoGlyph.element,\n });\n}\ninitMap();https://github.com/googlemaps-samples/js-api-samples/blob/5f4e6decfaf59cd69918bbf4e6338de03a63a5ba/dist/samples/advanced-markers-basic-style/docs/index.js#L8-L94\n```\n| **Note:** The JavaScript is compiled from the TypeScript snippet.\n\nCSS \n\n```css\n/* \n * Always set the map height explicitly to define the size of the div element\n * that contains the map. \n */\n#map {\n height: 100%;\n}\n\n/* \n * Optional: Makes the sample page fill the window. \n */\nhtml,\nbody {\n height: 100%;\n margin: 0;\n padding: 0;\n}\nhttps://github.com/googlemaps-samples/js-api-samples/blob/5f4e6decfaf59cd69918bbf4e6338de03a63a5ba/dist/samples/advanced-markers-basic-style/docs/style.css#L7-L24\n```\n\nHTML \n\n```html\n\u003chtml\u003e\n \u003chead\u003e\n \u003ctitle\u003eAdvanced Marker Basic Customization\u003c/title\u003e\n\n \u003clink rel=\"stylesheet\" type=\"text/css\" href=\"./style.css\" /\u003e\n \u003cscript type=\"module\" src=\"./index.js\"\u003e\u003c/script\u003e\n \u003c/head\u003e\n \u003cbody\u003e\n \u003cdiv id=\"map\"\u003e\u003c/div\u003e\n\n \u003c!-- prettier-ignore --\u003e\n \u003cscript\u003e(g=\u003e{var h,a,k,p=\"The Google Maps JavaScript API\",c=\"google\",l=\"importLibrary\",q=\"__ib__\",m=document,b=window;b=b[c]||(b[c]={});var d=b.maps||(b.maps={}),r=new Set,e=new URLSearchParams,u=()=\u003eh||(h=new Promise(async(f,n)=\u003e{await (a=m.createElement(\"script\"));e.set(\"libraries\",[...r]+\"\");for(k in g)e.set(k.replace(/[A-Z]/g,t=\u003e\"_\"+t[0].toLowerCase()),g[k]);e.set(\"callback\",c+\".maps.\"+q);a.src=`https://maps.${c}apis.com/maps/api/js?`+e;d[q]=f;a.onerror=()=\u003eh=n(Error(p+\" could not load.\"));a.nonce=m.querySelector(\"script[nonce]\")?.nonce||\"\";m.head.append(a)}));d[l]?console.warn(p+\" only loads once. Ignoring:\",g):d[l]=(f,...n)=\u003er.add(f)&&u().then(()=\u003ed[l](f,...n))})\n ({key: \"AIzaSyA6myHzS10YXdcazAFalmXvDkrYCp5cLc8\", v: \"weekly\"});\u003c/script\u003e\n \u003c/body\u003e\n\u003c/html\u003ehttps://github.com/googlemaps-samples/js-api-samples/blob/5f4e6decfaf59cd69918bbf4e6338de03a63a5ba/dist/samples/advanced-markers-basic-style/docs/index.html#L8-L22\n```\n\nTry Sample \n[JSFiddle.net](https://jsfiddle.net/gh/get/library/pure/googlemaps-samples/js-api-samples/tree/main/dist/samples/advanced-markers-basic-style/jsfiddle)\n\nClone Sample\n\n\nGit and Node.js are required to run this sample locally. Follow these [instructions](https://docs.npmjs.com/downloading-and-installing-node-js-and-npm) to install Node.js and NPM. The following commands clone, install dependencies and start the sample application. \n\n git clone https://github.com/googlemaps-samples/js-api-samples.git\n cd samples/advanced-markers-basic-style\n npm i\n npm start"]]