jQuery getScript和Google Maps API错误消息 [英] jQuery getScript and Google Maps API Error message

查看:109
本文介绍了jQuery getScript和Google Maps API错误消息的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我用自己的对象初始化了地图,google maps api通过加载jquery.getscript。但我总是会在回调函数中收到错误消息:

  var MyGMap = {
GMapScriptURL:http:/ /maps.google.com/maps?file=api&v=2&async=2&a​​mp;key=,
Map:null,
Geocoder:null,
InitiazlizeMaps:function() {
if(GBrowserIsCompatible()){
this.Map = new GMap2(document.getElementById(map_canvas));
this.Map.setCenter(new GLatLng(37.4419,-122.1419),13);
this.Geocoder = new GClientGeocoder();



$ b $(function(){
var CurrentKey =MY_KEY;

$。 getScript(MyGMap.GMapScriptURL + CurrentKey,function(){
MyGMap.InitiazlizeMaps();
// throws GMap2 is undefined

});
});

最新错误?为什么没有运行?

解决方案

您有 async = 2 在脚本URL行中,这意味着异步加载映射核心 - 您需要等待它完成之后才能调用InitializeMaps。您可以尝试从URL中删除 async = 2 ,或者使用Google Map的异步和回调代替getScript回调函数,例如

  $。getScript(MyGMap.GMapScriptURL + CurrentKey +& callback = MyGMap.InitializeMaps); 


I got a problem with loading the google maps api.

I got my own object with a function that initializes the map, and the google maps api gets loaded via jquery.getscript. but i always get an error message in the callback function:

var MyGMap = {
    GMapScriptURL: "http://maps.google.com/maps?file=api&v=2&async=2&key=",
    Map: null,
    Geocoder: null,
    InitiazlizeMaps: function () {
        if (GBrowserIsCompatible()) {
            this.Map = new GMap2(document.getElementById("map_canvas"));
            this.Map.setCenter(new GLatLng(37.4419, -122.1419), 13);
            this.Geocoder = new GClientGeocoder();
        }
    }
}

$(function(){
    var CurrentKey = "MY_KEY";

    $.getScript(MyGMap.GMapScriptURL + CurrentKey, function () {
        MyGMap.InitiazlizeMaps();
        // throws GMap2 is undefined

    });
});

whats wrong? why is this not running?

解决方案

You've got async=2 in the script URL line which means load the mapping core asynchronously too - you need to wait for it to complete that before you can call InitializeMaps. You can either try dropping the async=2 from the URL, or using Google Map's async and callback instead of the getScript callback function, e.g.

$.getScript(MyGMap.GMapScriptURL + CurrentKey + "&callback=MyGMap.InitializeMaps");

这篇关于jQuery getScript和Google Maps API错误消息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆