Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Sudden errors on Google Map: TypeError: _.x is not a function

I have a little Google Map with a few markers here: http://www.magicbad.com/kontakt/fachbetrieb-karte/

Since today (or maybe yesterday) there are suddenly errors popping up in the console, that I can't explain. The maps loads, but after a few seconds the errors pop up and you can't drag it anymore.

The code I use to initialize the map is (There is a little more to it with filters etc., but the errors pop up even when I switch off everything else):

google.load("maps", "3",  {other_params:"sensor=false"});

function initialize() {
    if($('.main.fullWidth').length > 0) var scroll = true;
    else var scroll = false;

    geocoder = new google.maps.Geocoder();

    var latlng = new google.maps.LatLng(48.3, 14.3);

    var myOptions = {
        zoom: myZoom,
        scrollwheel: scroll,
        center: latlng,
        mapTypeId: google.maps.MapTypeId.ROADMAP,
        navigationControl: true,
        navigationControlOptions: {
            style: google.maps.NavigationControlStyle.ZOOM_PAN,
            position: google.maps.ControlPosition.LEFT_BOTTOM
        }
    };

    map = new google.maps.Map(document.getElementById("map"), myOptions);
}

$(document).ready(function(){
    initialize();
});

The errors start of with: (few seconds after you load the page)

Uncaught TypeError: _.x is not a function / stats.js:9
Uncaught TypeError: Cannot set property 'Db' of undefined / common.js:216
Uncaught TypeError: a.set is not a function / js?v=3&sensor=false:38

And after that if you move your mouse over the map you get constant:

Uncaught TypeError: Failed to execute 'getComputedStyle' on 'Window': parameter 1 is not of type 'Element'. / common.js:31

Any ideas? The code might be messy, but this map has been up and running for years, why the sudden change?

Thank you for your help,

Florian

like image 434
Florian Rachor Avatar asked May 13 '26 18:05

Florian Rachor


1 Answers

Alright, I found the problem. I used an old form of including the Google Maps Api script. When I switch that to exactly this:

  <script async defer
      src="https://maps.googleapis.com/maps/api/js?key=YOUR_API_KEY&callback=initMap">
  </script>

As mentioned in the GM basic tutorial here: https://developers.google.com/maps/documentation/javascript/tutorial it starts working again.

So if you run across any errors of this type, first check if you API inclusion is up to date.

like image 160
Florian Rachor Avatar answered May 15 '26 06:05

Florian Rachor



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!