After displaying markers and markers with info windows, we will now display only info windows on the map. So our aim becomes, placing an info window on a google map when a user clicks on the map.
Now, the first question that will pop up in your mind is why do we need such a thing? To answer this question let us consider a simple example. Consider that, when an user clicks on a map, a marker appears with an info window and you want the user to enter some data in a form in the info window and save that data. Now, if the user enters inconsistent data, there would be marker on the map, having no valid information! The marker would then be rendered useless, with no information! Something like a dangling pointer!
Now, if you haven't understood a word of this; don't worry. You will soon understand the importance of this example! So, without any further discussions, let's have a look at the code!
Here goes the code...
Google Maps API v3 - Simple Info window example
map = new google.maps.Map(document.getElementById("map"),
center: new google.maps.LatLng(22.7964,79.5410),
var html = "This is an Info window without a marker.";
var infowindow = new google.maps.InfoWindow(
google.maps.event.addListener(map, 'click', function(event)
<body onload="click_window()" onunload="GUnload()">
<div id="map" style="width: 100%; height: 100%">
Copy and paste the above code in an html file and see the map in action! The output will look as seen in the picture below.