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

20,670

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.

Share:
20,670
Salman A
Author by

Salman A

Updated on January 18, 2020

Comments

  • Salman A
    Salman A over 4 years

    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?

  • Salman A
    Salman A about 13 years
    Does "undocumented" mean it may (not) work as expected or it may (not) work in the future?
  • HChen
    HChen about 13 years
    @Salman Well, turns out it's documented, just hidden deep inside the FAQ, rather than the documentation.
  • Salman A
    Salman A about 13 years
    Right... seems like v3 api still has a long way to go.
  • Sam Thornton
    Sam Thornton about 11 years
    This is a great answer! Just wanted to let you know you're missing a } at the end. You need to close the callback function and the .load function. }});
  • MattC
    MattC almost 11 years
    Just to add clarification to how the call would look if you setup your map in a separate function: google.load('maps', '3', {other_params:'sensor=true', "callback" : yourFunctionName});
  • user2636556
    user2636556 over 7 years
    how do you add your API key? i keep getting this warning on firebug Google Maps API warning: NoApiKeys https://developers.google.com/maps/documentation/javascript/‌​error-messages#no-ap‌​i-keys util.js (line 210)
  • Nilpo
    Nilpo over 6 years
    @user2636556 I have updated the answer to address this issue.
  • Nilpo
    Nilpo over 6 years
    I've updated this answer with currently working code. Love it when Google changes things without warning.