Javascript 使用google地图和require js异步插件不起作用
控制台的输出当我尝试从Javascript 使用google地图和require js异步插件不起作用,javascript,jquery,google-maps,google-maps-api-3,requirejs,Javascript,Jquery,Google Maps,Google Maps Api 3,Requirejs,控制台的输出当我尝试从main.js调用map.getZoom()时,控制台的输出似乎表明地图已加载但未显示: -34.397,150.644 maploader.js:19 the map was loaded maploader.js:11 The map is zoomed to 4 maploader.js:13 From main main.js:22 4 当我尝试使用requirejs模块显示地图时,地图不会显示,如下所示: gmaps.js maploader.js
main.js
调用map.getZoom()
时,控制台的输出似乎表明地图已加载但未显示:
-34.397,150.644 maploader.js:19
the map was loaded maploader.js:11
The map is zoomed to 4 maploader.js:13
From main main.js:22
4
当我尝试使用requirejs
模块显示地图时,地图不会显示,如下所示:
gmaps.js
maploader.js
main.js
这是我的目录结构:
~/Desktop/maps/modules_test $ ls -LR
.:
css index.html scripts
./css:
init.css
./scripts:
gmaps.js lib main.js maploader.js
./scripts/lib:
jquery.min.js plugins require.js
./scripts/lib/plugins:
async.js font.js image.js mdown.js propertyParser.js
depend.js goog.js json.js noext.js
更新:
这也不起作用,更糟糕的是,它甚至不打印我的控制台日志
require(['./gmaps','./maploader'],function(gmaps,map){
var initialize=function()
{
var myDiv=document.getElementById('map-canvas');
var center=map.createLatLng(-34.397, 150.644);
var myMap=map.fetchMap(myDiv,center,4);
console.log('From main');
console.log(''+myMap.getZoom());
};
gmaps.event.addDomListener(window,'load',initialize);
});
函数
createLatLng()
不返回中心值:
createLatLng:function(lat,lng)
{
var p=new gmaps.LatLng(lat,lng);
console.log(p.lat()+','+p.lng());
}
没有
返回p代码>声明。你不知道我离目标有多远,我只是在要求后检查了整个文档的html,gmaps修改了它以寻找线索。谢谢
~/Desktop/maps/modules_test $ ls -LR
.:
css index.html scripts
./css:
init.css
./scripts:
gmaps.js lib main.js maploader.js
./scripts/lib:
jquery.min.js plugins require.js
./scripts/lib/plugins:
async.js font.js image.js mdown.js propertyParser.js
depend.js goog.js json.js noext.js
require(['./gmaps','./maploader'],function(gmaps,map){
var initialize=function()
{
var myDiv=document.getElementById('map-canvas');
var center=map.createLatLng(-34.397, 150.644);
var myMap=map.fetchMap(myDiv,center,4);
console.log('From main');
console.log(''+myMap.getZoom());
};
gmaps.event.addDomListener(window,'load',initialize);
});
createLatLng:function(lat,lng)
{
var p=new gmaps.LatLng(lat,lng);
console.log(p.lat()+','+p.lng());
}