2

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

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=... 保留在 url 中并注释掉手动加载的“ google.load("maps", "2.x");”,它仍然不起作用。

关于如何正确使用自动加载功能以获得最大性能(最小延迟)的任何想法?

4

1 回答 1

0

你应该使用:

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

别的什么都没有。在您的示例中删除此之后的代码

于 2009-10-10T00:57:55.517 回答