我正在努力加載gmaps API與requireJS。這是我已經試過:如何使用RequireJS加載Google Maps 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? – 2013-04-03 19:11:12
沒有它未被加載... – hjuster 2013-04-03 19:16:36
這個答案可能有幫助 - http://stackoverflow.com/questions/6398342/cant-initiate-the-google-maps-geocoder。我沒有API密鑰,因此可能無法完全適用於我。似乎必須要求加載Geocoder。 – 2013-04-03 19:26:36