Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Google Maps API: TypeError: a is undefined

I have searched this problem all over the web and none of them seem to give me any resolution. I have a simple script to just display the map of South Africa.

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta http-equiv="x-ua-compatible" content="ie=edge, chrome=1" />
<title>Map Test</title>
<script language="javascript" src="https://maps.googleapis.com/maps/api/js?sensor=true"></script>
<style>
#map-canvas {
    height: 300px;
    width: 980px;
    margin: 0;
    padding: 0;
    margin-top: 10px;
}
</style>
</head>
<body>
<div id="map-canvas" class="map_canvas"></div>
<script type="text/javascript">
    function initialize()
    {
        var mapOptions = {
            center: new google.maps.LatLng(-29.09958,26.18434),
            zoom: 5,
            mapTypeControlOptions: {
                position: google.maps.ControlPosition.TOP_LEFT
            }
        };
        map = new google.maps.Map(document.getElementById('map-canvas'),mapOptions);
    }
    google.maps.event.addDomListener(window, 'load', initialize);
</script>
</body>
</html>

But I keep on getting the same error over and over. I have even tried on a different server.

enter image description here

Please help

like image 472
PHP Noob Avatar asked Sep 21 '15 09:09

PHP Noob


3 Answers

I've also seen this error often in the last days, there seems to be an issue with the experimental API-version.

Load the release-version instead(basically you should always load the release-version in production)

<script language="javascript" src="https://maps.googleapis.com/maps/api/js?sensor=true&v=3"></script>
like image 124
Dr.Molle Avatar answered Sep 29 '22 04:09

Dr.Molle


Google Maps started to through errors when loading the script and on touch events. I'm using it for a cordova application on Android and iOS.enter image description here

These are the errors I get but changing the load version didn't solve it.

<script type="text/javascript" src="https://maps.googleapis.com/maps/api/js?key=MYKEY&v=3.21&libraries=geometry,places"></script>
like image 38
Daniela Avatar answered Sep 29 '22 05:09

Daniela


Version 3.30+ is affected of this problem if there is a global var called Map.

ex:

<script type="text/javascript" src="https://maps.googleapis.com/maps/api/js?key=YOURKEYHERE&v=3&callback=init" async defer></script>
<script type="text/javascript">
    function init() {
        Map.go();
    }
    var Map = {
        go: function() {
            console.log("start engine");
        }
    };
</script>

We got this error:

TypeError: a.prototype is undefined

Renaming window.Map then everything goes fine.

like image 1
Luca Rainone Avatar answered Sep 29 '22 04:09

Luca Rainone