如何使用 Google 地图“自动加载” 功能?

发布于 2024-07-21 06:41:03 字数 1306 浏览 5 评论 0原文

我开始阅读有关自动加载谷歌地图的内容:

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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

泪眸﹌ 2024-07-28 06:41:03

您应该使用:

<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>

没有其他任何东西。 在您的示例中删除此后的代码

You should use:

<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>

Any nothing else. Remove the code after this in you example

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文