开发者

Google Maps Apiv3 + Load map on page load + a is NULL

开发者 https://www.devze.com 2023-04-09 07:48 出处:网络
First of all: The map is working. The script is in scripts.js, which is included at the bottom of the site.

First of all: The map is working.

The script is in scripts.js, which is included at the bottom of the site.

The Google maps script is included in the header (<script src="http://maps.googleapis.com/maps/api/js?sensor=false"></script>).

The problem is I am getting this a is NULL error and I would like to fix it, although the map is working fine.

I have searched Google and Stackoverflow and tried every possible combination of the answers I found, but either the map is not working, or the map is working, but I get this a is NULL error error.

Here is the simple demo script I am using for testing:

function init() {

        var myOptions = {
          zoom: 8,
     开发者_Python百科     center: new google.maps.LatLng(-34.397, 150.644),
          mapTypeId: google.maps.MapTypeId.ROADMAP
        };
        map = new google.maps.Map(document.getElementById('resultsGmap'),
            myOptions);

}

window.onload=init();

I have tried to use jQuery too like this:

$(function() {

    init();

});

But than nothing works at all. I have also tried to do it very simple like this:

init();

Which works (the map works) but the a is NULL error error appears again.

The other thing I tried was:

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

But than again the map doesn't display and the error appears.

For various reason I cant do it the way it is in the official example @ Google:

<body onload="init()">

Anybody got an idea what I am doing wrong?

Regards and have a good day!

EDIT:

I have just tried to reproduce the error on a blank page and there it doesnt appear - so I guess it is something else in my code (p.s. I am loading the site with the map via ajax and call the script with $.getScript).

Sorry that I didnt check that before. I guess the error lies in there somewhere.

One more thing: Do you guys think it would be very, very bad to just ignore the error? Since the map and every feature is working correctly.


I'm suspecting it has to do with the ID you provide. Is there a (for example) DIV with the ID 'resultsGmap'.

It might have also got to do with the uppercase. Try using lowercase only, optionally with underscores (_)

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号