google.maps.Marker zIndex doesn’t work for two icon types – Symbol and String

You have to both specify a zIndex and add

optimized: false

to every marker constructor, eg.

var marker = new google.maps.Marker({
    position: markerLatLng,
    map: map,
    icon: resultIcon,
    optimized: false,
    zIndex: 5

This seems to be an issue with the new canvas based rendering of the markers.


This really solves the issue. One thing to mention though is that every marker has to have the “optimized: false” attribute. As long as one marker does not have it, it will not work.

Remove any of the “optimized: false” attributes from LeJared’s fiddle and you will encounter the bug.


Google Map API v3 ~ Simply Close an infowindow?

With the v3 API, you can easily close the InfoWindow with the InfoWindow.close() method. You simply need to keep a reference to the InfoWindow object that you are using. Consider the following example, which opens up an InfoWindow and closes it after 5 seconds:

<!DOCTYPE html>
  <meta http-equiv="content-type" content="text/html; charset=UTF-8"/> 
  <title>Google Maps API InfoWindow Demo</title> 
  <script src="" 
  <div id="map" style="width: 400px; height: 500px;"></div>

  <script type="text/javascript">
    var map = new google.maps.Map(document.getElementById('map'), {
      zoom: 4,
      center: new google.maps.LatLng(-25.36388, 131.04492),
      mapTypeId: google.maps.MapTypeId.ROADMAP

    var marker = new google.maps.Marker({
      position: map.getCenter(),
      map: map

    var infowindow = new google.maps.InfoWindow({
      content: 'An InfoWindow'
    });, marker);

    setTimeout(function () { infowindow.close(); }, 5000);

If you have a separate InfoWindow object for each Marker, you may want to consider adding the InfoWindow object as a property of your Marker objects:

var marker = new google.maps.Marker({
  position: map.getCenter(),
   map: map

marker.infowindow = new google.maps.InfoWindow({
  content: 'An InfoWindow'

Then you would be able to open and close that InfoWindow as follows:, marker);

The same applies if you have an array of markers:

var markers = [];

marker[0] = new google.maps.Marker({
  position: map.getCenter(),
   map: map

marker[0].infowindow = new google.maps.InfoWindow({
  content: 'An InfoWindow'

// ...

marker[0], marker);