views:

457

answers:

1

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

A: 

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

tim