【发布时间】:2013-03-25 14:36:53
【问题描述】:
我正在努力使用 requireJS 加载 gmaps api。这是我尝试过的:
requirejs.config({
urlArgs: "noCache=" + (new Date).getTime(),
paths : {
"jquery": "vendor/jquery-1.8.2.min",
"bootstrap": "vendor/bootstrap.min",
"underscore": "libs/underscore-min",
"backbone": "libs/backbone-min",
"template": "libs/template",
"gmaps": "http://maps.google.com/maps/api/js?v=3&sensor=false"
},
shim: {
'backbone': {
deps: ['jquery', 'underscore'],
exports: 'Backbone'
},
'underscore': {
exports: '_'
},
'bootstrap': {
deps: ['jquery']
},
'gmaps': {
deps: ['jquery']
},
'main':{
deps: ['jquery','gmaps']
}
}
});
require(["main"], function (main) {})
但在 main.js 中,当我尝试实例化我得到的地理编码器时,未定义不是函数”错误。
var geocoder = new google.maps.Geocoder();
任何想法我可能做错了什么?
【问题讨论】:
-
是否有网络错误?地图 api JS 真的在加载吗?
-
没有它没有被加载...
-
这个答案可能会有所帮助 - stackoverflow.com/questions/6398342/…。我没有 API 密钥,因此它可能无法完全为我工作。似乎必须请求加载地理编码器。
-
能否请您展示您如何从 configure.js 中定义的 gmap 转到新的 google.maps.Geocoder()?
标签: google-maps-api-3 requirejs js-amd