Google Maps JavaScript API Error In Internet Explorer

前端 未结 2 1294
挽巷
挽巷 2021-01-24 03:07

I have written a really simple jQuery Plugin for the Google Maps JavaScript API v3.

It is working in Firefox, Chrome (et al), but not Internet Explorer 8.

The er

相关标签:
2条回答
  • 2021-01-24 03:19

    I think it's just a matter of timing. Try making this call from the html:

    $("#map").simplemap({ search: "Buckingham Palace, London", description: "Buckingham Palace,<br>London" });
    

    on ready:

    $.ready(function() {
      $("#map").simplemap({ search: "Buckingham Palace, London", description: "Buckingham Palace,<br>London" });
    });
    
    0 讨论(0)
  • 2021-01-24 03:32

    Okay, I have found a solution to this problem.

    The error raised from inside the Google Maps API is caused by the scope of the variable being used to store the map. All of the examples for the API use something like this...

    map = new google.maps.Map(mapContainer, myOptions);
    

    Note that "map" is one of these wonderful mystery-scope variables... and I'm running all of this code inside of my jQuery Plugin - so the end result is that the Google Maps API cannot get a handle on the map variable.

    By declaring map as a Global variable, Google Maps API can access it and everything magically starts working perfectly.

    So the fix is to declare...

    var map;
    

    In the Global scope, so the API can get to it.

    0 讨论(0)
提交回复
热议问题