如何在 json 文件已经加载后加载 googlemap?
How to after json file already load and then load googlemap?
我通过javascript回调函数
使用googlemap
<script>
jsonmap={};
jqxhr=$.getJSON("postheat.json",function(data){
return data}).done(function(data){
jsonmap=data;
return data;
});
function initMap(){
mapjson.....;
}
</script>
<script src="//maps.google.com/maps/api/js?sensor=true&callback=initMap"></script>
但是我发现当我initMap的时候,json数据还没有准备好。如何确定json数据已经加载,然后执行initMap函数。
在 done
块中完成调用后尝试调用 initmap
:
jsonmap={};
jqxhr = $.getJSON("postheat.json",function(data){
jsonmap=data;
//try adding script to the page here:
var s=document.createElement("script");
s.src="//maps.google.com/maps/api/js?sensor=true&callback=initMap";
document.head.appendChild(s);
});
function initMap(){
mapjson.....;
}
但我确信有更好的方法。试试你是否可以从地图文档中获得一些东西。
我通过javascript回调函数
使用googlemap<script>
jsonmap={};
jqxhr=$.getJSON("postheat.json",function(data){
return data}).done(function(data){
jsonmap=data;
return data;
});
function initMap(){
mapjson.....;
}
</script>
<script src="//maps.google.com/maps/api/js?sensor=true&callback=initMap"></script>
但是我发现当我initMap的时候,json数据还没有准备好。如何确定json数据已经加载,然后执行initMap函数。
在 done
块中完成调用后尝试调用 initmap
:
jsonmap={};
jqxhr = $.getJSON("postheat.json",function(data){
jsonmap=data;
//try adding script to the page here:
var s=document.createElement("script");
s.src="//maps.google.com/maps/api/js?sensor=true&callback=initMap";
document.head.appendChild(s);
});
function initMap(){
mapjson.....;
}
但我确信有更好的方法。试试你是否可以从地图文档中获得一些东西。