如何使用 Google 地图“自动加载” 功能?
我开始阅读有关自动加载谷歌地图的内容:
http://code.google .com/apis/ajax/documentation/#AutoLoading
我不清楚的是如何实际加载谷歌地图。
我尝试过:
<script src="http://www.google.com/jsapi?autoload=%7B%22modules%22%3A
%5B%7B%22name%22%3A%22search%22%2C%22version%22%3A%221.0%22%2C
%22language%22%3A%22en%22%7D%2C%7B%22name%22%3A%22maps%22%2C%22version
%22%3A%222.X%22%7D%2C%7B%22name%22%3A%22elements%22%2C%22version%22%3A
%221.0%22%2C%22packages%22%3A%5B%22localsearch%22%5D%7D%5D
%7D&key=MY_KEY"></script>
<script type="text/javascript">
//<![CDATA[
google.load("maps", "2.x");
google.setOnLoadCallback(function() {
map = new google.maps.Map2(document.getElementById("map"));
map.setCenter(new GLatLng(37.4419, -122.1419), 6);
map.addControl(new GSmallMapControl());
}
);
//]]>
</script>
但地图无法加载。
奇怪的是,如果我只是从地图中删除“autoload=
...” URL - 地图加载并正常工作。
如果我在网址中保留 autoload=
... 并注释掉手动加载“google.load("maps", "2.x");
”,它仍然不起作用。
关于如何正确使用自动加载功能来获得的任何想法 最高性能(最低延迟)?
I began reading about Auto-loading a google map at:
http://code.google.com/apis/ajax/documentation/#AutoLoading
What's unclear to me is how to actually load the google map.
I have tried:
<script src="http://www.google.com/jsapi?autoload=%7B%22modules%22%3A
%5B%7B%22name%22%3A%22search%22%2C%22version%22%3A%221.0%22%2C
%22language%22%3A%22en%22%7D%2C%7B%22name%22%3A%22maps%22%2C%22version
%22%3A%222.X%22%7D%2C%7B%22name%22%3A%22elements%22%2C%22version%22%3A
%221.0%22%2C%22packages%22%3A%5B%22localsearch%22%5D%7D%5D
%7D&key=MY_KEY"></script>
<script type="text/javascript">
//<![CDATA[
google.load("maps", "2.x");
google.setOnLoadCallback(function() {
map = new google.maps.Map2(document.getElementById("map"));
map.setCenter(new GLatLng(37.4419, -122.1419), 6);
map.addControl(new GSmallMapControl());
}
);
//]]>
</script>
But the map doesn't load.
Strange thing is that if I simply remove the "autoload=
..." from the
URL - the map loads and works fine.
If I keep the autoload=
... in the url and comment out the manually loading "google.load("maps", "2.x");
", it still doesn't work.
Any ideas on how to properly use the auto-load functionality to gain
the most performance (least latency)?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您应该使用:
没有其他任何东西。 在您的示例中删除此后的代码
You should use:
Any nothing else. Remove the code after this in you example