This example adds markers to a map, using <gmp-advanced-marker>.
Read the documentation.
TypeScript
// This example adds a map with markers, using web components. async function initMap() { console.log('Maps JavaScript API loaded.'); } initMap();
JavaScript
// This example adds a map with markers, using web components. async function initMap() { console.log('Maps JavaScript API loaded.'); } initMap();
CSS
/* Note: This CSS file is intentionally blank. */
HTML
<html>
<head>
<title>Add a Map with Markers using HTML</title>
<style>
gmp-map {
height: 100%;
}
html,
body {
height: 100%;
margin: 0;
padding: 0;
}
</style>
<script type="module" src="./index.js"></script>
<script
src="https://maps.googleapis.com/maps/api/js?key=AIzaSyA6myHzS10YXdcazAFalmXvDkrYCp5cLc8&libraries=maps,marker&v=weekly&internal_usage_attribution_ids=gmp_git_jsapisamples_v1_web-components"
defer></script>
</head>
<body>
<gmp-map
center="41.027748173921374, -92.41852445367961"
zoom="13"
map-id="DEMO_MAP_ID">
<gmp-advanced-marker
position="41.027748173921374, -92.41852445367961"
title="Ottumwa, IA"></gmp-advanced-marker>
</gmp-map>
</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 https://github.com/googlemaps-samples/js-api-samples.gitcd samples/web-components-markersnpm inpm start