Can you load Google Maps API v3 via Google AJAX API loader

Salman A picture Salman A · Mar 14, 2011 · Viewed 20.6k times · Source

Some time ago I used the regular method of loading Google Maps API like this:

<script type="text/javascript" src="http://maps.google.com/maps?file=api&v=2&key=abcdefg&sensor=true">

Later I switched to Google AJAX APIs to load Google Maps API. This was because a couple of "widgets" on my website needed the Google Ajax API loader so I chose to be consistent and used the AJAX APIs to load Google Maps as well:

<script type="text/javascript" src="http://www.google.com/jsapi?key=abcdef"></script>
<script type="text/javascript">
  google.load("maps", "2", {"other_params": "sensor=true"});
</script>

Now that I have finally decided to use Google Maps API v3, this page does not list API v3 in the available version list. None of the examples on API v3 documentation show the use of AJAX APIs as well. Is is possible (and supported) to load Google Maps API v3 via AJAX API loader?

Answer

Haochi picture Haochi · Mar 14, 2011

It's undocumented, but it works.

google.load("maps", "3", {other_params:'key=YOUR_API_KEY', callback: function(){
  var map; // initialize your map in here
}});

[EDIT] The documentation now requires the use of an API key that is passed to the loader as a "key" parameter. I've removed 'sensor=false' as a parameter because it is now explicitly not required and throws a warning when provided.