Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Google Maps Uncaught TypeError: b.has is not a function

We are including the Google Maps API V3 in our internal systems with the below code:

script src="https://maps.googleapis.com/maps/api/js?key=&libraries=places,geometry"

This was working until a few hours ago (9am AEST) now in the console all that's returned is:

Uncaught TypeError: b.has is not a function from https://maps.googleapis.com/maps-api-v3/api/js/35/3/map.js

Is anyone else facing the same problem?

How can I fix it when the code is included from Google's servers?

like image 986
JRT2018 Avatar asked Nov 28 '18 02:11

JRT2018


2 Answers

Had the same problem, using an older version fixed it for now:

https://maps.googleapis.com/maps/api/js?v=quarterly&key=API_KEY

Long time fix - You probably overwrote the native window.Map, see https://developer.mozilla.org/de/docs/Web/JavaScript/Reference/Global_Objects/Map

like image 156
Krisdigital Avatar answered Oct 25 '22 02:10

Krisdigital


We have the same problem here. We had a link to the last version : https://maps.googleapis.com/maps/api/js?key=...

If we force the version to 3.34 it does the trick : https://maps.googleapis.com/maps/api/js?v=3.34&key=

Version 3.35 is not working. Google has replaced a function used with maps (hashmaps, not graphic maps) which is used to search for a key. hasOwnProperty(b, c) --> b.has(c)

Problem is that "b" does not have the function "has".

I do not have much more information at this point. We are continuing the investigation.

Good luck everyone.

Regards Vincent

Edit : OK, now I do understand what happened. Somewhere in our map, we are re-defining the prototype "Map". This protoype does not contain the method "has" and maybe "set" too (that was the case for us). You have to search for something like "Map.prototype." in jour JS files. This will give you the hint for where you have to correct your JS. If you can't suppress this prototype, you will have to redefine the missing methods. For example, we had the following prototype :

function Map(){
    this.obj = {};
    this.count = 0;
}

We had to complete this prototype with the following methods :

Map.prototype.has=function(key){
    return this.obj[key] !== undefined;
}

Map.prototype.set = function(key, value){
    var oldValue = this.obj[key];
    if(oldValue == undefined){
        this.count++;
    }
    this.obj[key] = value;
    return oldValue;
}

With this correction, version 3.35 of GoogleMaps JS is working.

I hope it helps.

Regards, Vincent

like image 25
Vincent Coulon Avatar answered Oct 25 '22 04:10

Vincent Coulon