JSFiddle - React, Tailwind, and code Playground
HTML
<script src="https://maps.google.com/maps/api/js"></script>
<div id="maps">
<div id="map-1"></div>
<div id="map-2"></div>
</div>
CSS
.map {
height: 300px;
margin: 10px;
}
JavaScript
[
{
el: '#map-1',
center: [ 55.7708, 37.5967 ],
markers: [
[ 55.8, 37.4 ],
[ 55.7, 37.7 ],
[ 55.6, 37.5 ],
],
},
{
el: '#map-2',
center: [ 34.0522, -118.2437 ],
markers: [
[ 34.1, -118.2 ],
[ 34.0, -118.3 ],
[ 33.9, -118.0 ],
],
},
].forEach(initMap);
function initMap({ el, center, markers }) {
el = document.querySelector(el);
el.classList.add('map');
const map = new google.maps.Map(el, {
center: new google.maps.LatLng(...center),
zoom: 9,
});
markers.forEach(([ lat, lng ]) => {
new google.maps.Marker({
position: { lat, lng },
map,
});
});
}