JSFiddle - React, Tailwind, and code Playground
HTML
<script src="https://maps.googleapis.com/maps/api/js?sensor=false"></script>
<div id="map_canvas" style="height:400px"></div>
JavaScript
function initialize() {
var myLatlng = new google.maps.LatLng(-25.363882,131.044922);
var mapOptions = {
zoom: 4,
center: myLatlng,
mapTypeId: google.maps.MapTypeId.ROADMAP
}
var map = new google.maps.Map(document.getElementById('map_canvas'), mapOptions);
var contentStringCal = '<div id="contentCal">contentStringCal</div>';
var infowindow = new google.maps.InfoWindow({});
var CalMarker = new google.maps.Marker({
position: myLatlng,
map: map,
title: 'Uluru (Ayers Rock)'
});
google.maps.event.addListener(CalMarker, 'mouseover', function() {
//open the infowindow when it's not open yet
if(contentStringCal!=infowindow.getContent())
{
infowindow.setContent(contentStringCal);
infowindow.open(map,CalMarker);
}
});
google.maps.event.addListener(CalMarker, 'click', function() {
//when the infowindow is open, close it an clear the contents
if(contentStringCal==infowindow.getContent())
{
infowindow.close(map,CalMarker);
infowindow.setContent('');
}
//otherwise trigger mouseover to open the infowindow
else
{
google.maps.event.trigger(CalMarker, 'mouseover');
}
});
//clear the contents of the infwindow on closeclick
google.maps.event.addListener(infowindow, 'closeclick', function() {
infowindow.setContent('');
});
}