JSFiddle - React, Tailwind, and code Playground
HTML
<div id="map"></div>
<script async src="https://maps.googleapis.com/maps/api/js?callback=initialize"></script>
CSS
body {
margin: 0;
}
#map {
height: 100vh;
}
.red {
color: red;
}
JavaScript
function initialize() {
const map = new google.maps.Map(document.getElementById('map'), {
zoom: 12,
center: new google.maps.LatLng(59.928242, 30.347073),
});
const infowindow = new google.maps.InfoWindow();
google.maps.event.addListener(map, 'click', function() {
infowindow.close();
});
const markerData = [
{ coord: [ 59.939175, 30.327326 ], content: '<span class="red">hello, world!!</span>' },
{ coord: [ 59.938830, 30.339343 ], content: '<b>fuck the world</b>' },
{ coord: [ 59.944133, 30.227353 ], content: '<p style="font-size: 2em;">fuck everything</p>' },
];
markerData.forEach(function(n) {
const marker = new google.maps.Marker({
position: new google.maps.LatLng(...n.coord),
map,
});
marker.addListener('click', function() {
infowindow.setContent(n.content);
infowindow.open(map, marker);
});
});
}