Hi there, using the google maps component, how am i able to add multiple markers rather than just one address?
Thank you.
Hi there, using the google maps component, how am i able to add multiple markers rather than just one address?
Thank you.
So far I’ve got this code:
<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
async
src="https://maps.googleapis.com/maps/api/js?loading=async&key=******2TV3sAd-QwS_bu_yvhJjQhga1fA&libraries=maps,marker"></script>
</head>
<body>
<gmp-map
center="51.54609979351465, 11.602242228912166"
zoom="2"
map-id="DEMO_MAP_ID">
<gmp-advanced-marker
position="53.48059463593195, -2.2389147610283655"
title="Manchester, UK"></gmp-advanced-marker>
<gmp-advanced-marker
position="51.512717839210254, -0.10435506996064603"
title="London, UK"></gmp-advanced-marker>
</gmp-map>
</body>
</html>
However I’m not sure how to add this into BSS to display on the website.
I’ve tried adding the contents of body into a custom code component and the head in the page’s head options, and alternatively both in the same code block but it’s not rendering on the website. Any help on how to add this code into the design?
According to Google’s AI, Gemini…
Embedding a Google Map with multiple markers is very common, and you can achieve it in one of two ways depending on your technical comfort level: the easy way (no coding required) using Google My Maps, or the developer way using the Google Maps JavaScript API.
Best for: Non-developers, small businesses, event pages, or anyone wanting a quick visual setup without writing code.
Create your map:
Go to Google My Maps.
Click Create a new map.
Add your markers:
Use the search bar at the top to find your locations, or click the Add marker pin icon below the search bar to drop pins manually.
Customize the titles, descriptions, colors, and icons for each pin as needed.
Make the map public:
Click the Share button in the left panel.
Change the link sharing settings so that “Anyone with this link can view” is enabled.
Get the embed code:
Click the three-dot menu icon next to the map title in the left sidebar.
Select Embed on my site.
Copy the <iframe> HTML code provided.
Paste into your website:
<iframe> code directly into the HTML editor of your website platform (WordPress, Squarespace, Webflow, custom HTML, etc.).Best for: Custom web apps, dynamic data pulling from a database, or when you need complete control over styling and interactivity.
Get an API Key:
Add the HTML container and script:
<div> where the map will live and load the Google Maps script with your API key.Here is a clean, modern code example using an array of locations:
HTML
<!DOCTYPE html>
<html>
<head>
<title>Multiple Markers Map</title>
<style>
#map {
height: 500px;
width: 100%;
}
</style>
</head>
<body>
<h3>Our Locations</h3>
<div id="map"></div>
<!-- Load the Google Maps JavaScript API -->
<script>
async function initMap() {
// Request needed libraries
const { Map } = await google.maps.importLibrary("maps");
const { AdvancedMarkerElement } = await google.maps.importLibrary("marker");
// Center the map (e.g., New York City)
const map = new Map(document.getElementById("map"), {
zoom: 12,
center: { lat: 40.7128, lng: -74.0060 },
mapId: "YOUR_MAP_ID_HERE", // Optional, required for Advanced Markers styling
});
// Define your array of locations
const locations = [
{ lat: 40.7128, lng: -74.0060, title: "Location A" },
{ lat: 40.7306, lng: -73.9352, title: "Location B" },
{ lat: 40.6782, lng: -73.9442, title: "Location C" }
];
// Loop through locations and add markers
locations.forEach(loc => {
const marker = new AdvancedMarkerElement({
map: map,
position: { lat: loc.lat, lng: loc.lng },
title: loc.title,
});
});
}
initMap();
</script>
<!-- Replace YOUR_API_KEY with your actual Google Maps API key -->
<script async src="https://maps.googleapis.com/maps/api/js?key=YOUR_API_KEY&callback=initMap"></script>
</body>
</html>
Tip: If you just want a standard map without custom map IDs, you can use the traditional
google.maps.Markerinstead ofAdvancedMarkerElement, though Google encourages migrating to the newer advanced markers for future compatibility.
Choose Method 1 (My Maps) if you just want to copy-paste an iframe in 5 minutes.
Choose Method 2 (API) if your locations change dynamically based on user input or a database backend.
I managed to get this working eventually by myself. Although, not sure what i did to make it work haha.