Eva Martin
Eva Martin

Reputation: 31

Uncaught TypeError: window.Map is not a constructor

I've got a problem at https://haut-poitou.fr/categories/ Since a few days, i got an error :

map.js:2 Uncaught TypeError: window.Map is not a constructor
    at Xr (map.js:2)
    at bs.setZIndex (map.js:54)
    at ds.He (map.js:57)
    at _.pl.Bb (map.js:60)
    at Ot (map.js:44)
    at map.js:45

It appears on each page with a map somewhere in it, and repeats, sometimes up to 50 or more errors. The map seems to geolocate somehow, but the background is missing, only pins appear.
I tried to deactivate/reactivate all plugins, wordpress version is updated, with no effect on the issue.
I found some topics here and there to solve the issue, like here :
window.Map is not a constructor in Google Maps API v3 but unfortunately i'm total noob with this and I don't even know where i'm supposed to custom the code.
If anybody could help me with this, it would be so awesome !
Thank you

Upvotes: 3

Views: 4544

Answers (2)

Burndog
Burndog

Reputation: 719

MrSethT offers a more complete solution. Adding the version number back to 3.34 does work, but as noted it will fail later when 3.34 is retired.

Here is our working script where the variable map is changed to varmap

<script>
// Initialize and add the map
function initMap() {
  // The location of mapTarget
  var mapTarget = {lat: 9.941625, lng: -85.660698};
  // The map, centered at mapTarget
  var varmap = new google.maps.Map(
      document.getElementById('map'), {zoom: 16, center: mapTarget});

  var contentString = 
      '<h3 id="firstHeading" class="firstHeading">Le Cabanon</h3>'+
      'W8RQ+JP Playa Guiones,<br />Guanacaste Province, Costa Rica';

  var infowindow = new google.maps.InfoWindow({
    content: contentString
  });

  var marker = new google.maps.Marker({
    position: mapTarget,
    map: varmap,
    animation: google.maps.Animation.DROP,
    title: 'Le Cabanon'
  });
  marker.addListener('click', function() {
    infowindow.open(map, marker);
  });
}
 </script>

Upvotes: 2

MrSethT
MrSethT

Reputation: 53

It's caused by a new version of Maps being released. Fall back to v3.34 for now, but that is not a permanent fix since v.3.34 will be eventually unavailable. See if you have a variable named "Map" anywhere that you can rename so it doesn't conflict with their "Map".

Upvotes: 2

Related Questions