Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>Not saying the best way to do it is this, but a marker object sure can have an infoWindow as one of it's properties! Google's API doesn't restrict/throw errors when you put random properties/methods on it's marker objects. The following is perfectly valid code:</p> <pre><code>var someMarker = new google.maps.Marker(properties); someMarker.infoWindow = new google.maps.InfoWindow(properties); someMarker.infoWindow.setMap(map); someMarker.infoWindow.open(); </code></pre> <p>That being said, on a lot of google maps implantations there's generally only a single infoWindow object on the map. The reason for this if you opened up 4 or 5 infoWindows in a single map view, they tend to clutter up the map and you can't see any of the base map tiles anymore. </p> <p>For that reason, you can have a single infoWindow object, and just change the contents of it, depending on which marker is clicked:</p> <pre><code>var yourGlobalInfoWindow = new google.map.InfoWindow(properties); var someMarkerA = new google.maps.Marker(properties); var someMarkerB = new google.maps.Marker(properties); someMarkerA.infoWindowContent = 'some A HTML content here'; someMarkerB.infoWindowContent = 'some B HTML content here'; google.maps.event.addListener(someMarkerA,'click',function() { yourGlobalInfoWindow.setContent(someMarkerA.infoWindowContent); }); google.maps.event.addListener(someMarkerB,'click',function() { yourGlobalInfoWindow.setContent(someMarkerB.infoWindowContent); }); </code></pre> <p>Note that the code above is for illustrative purposes only and is far from optimized or elegant, but it gets the point across.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload