raviramani
raviramani

Reputation: 522

Uncaught ReferenceError: google is not defined in google maps

getting error in java script all things works normal then why give this error, i won't able to run the code which is written below this and this is google function which is important to use so how can i remove or is there any other way to solve the error

//Error is given on this line
google.maps.event.addDomListener(window, 'load', initGoogleMap);

//because of error this code not works
        google.maps.event.addListener(marker, 'click', function() {
            if(!marker.open){
                infoWindow.open(map,marker);
                marker.open = true;
            }
            else{
                infoWindow.close();
                marker.open = false;
            }
            google.maps.event.addListener(map, 'click', function() {
                infoWindow.close();
                marker.open = false;
            });
        });

Upvotes: 1

Views: 539

Answers (1)

Code Lღver
Code Lღver

Reputation: 15603

google.maps.event.addDomListener(window, 'load', initGoogleMap);

Above code is for calling the function initGoogleMap at the time of window load. So there will be following reason of giving the error:

  1. The function initGoogleMap you have not defined.
  2. This is calling before the google map library load.

To resolve this follow the below statements:

  • Remove or comment this line.
  • Add the code onload = initGoogleMap() in the body tag. After that your body tag will be like this:

<body onload = initGoogleMap()>

Hope it will help you. If you have any query, asked me.

Upvotes: 1

Related Questions