1

I am trying to load Google API dynamically using getScript() method for "Place Autocomplete Address Form". ( https://developers.google.com/maps/documentation/javascript/examples/places-autocomplete-addressform )

Here's the code I came up with:

$.getScript( 'https://maps.googleapis.com/maps/api/js?sensor=false&libraries=places', function( data, textStatus, jqxhr ) {
    console.log( data ); // Data returned
    console.log( textStatus ); // Success
    console.log( jqxhr.status ); // 200
    console.log( "Load was performed." );
});

But I'm getting the following error message form my console:

ReferenceError: Can't find variable: google
undefined
success
200
Load was performed.

Any idea on how to fix that?

4
  • do u have firebug installed in firefox? Commented Apr 20, 2014 at 7:08
  • no I don't, the console returns that on firefox "A call to document.write() from an asynchronously-loaded external script was ignored." Commented Apr 20, 2014 at 7:10
  • I just ran your code and it was loaded successfully for me. I included jquery 1.10.1. Commented Apr 20, 2014 at 7:12
  • I tested it on a separate file from scratch, got rid of the error but returned data is still "undefined" and autocomplete not working, Under jquery 1.11.0 Commented Apr 20, 2014 at 7:45

1 Answer 1

0

Check if this fiddle helps you.. jsfiddle .It loads the script dynamically and generates map.

.
Sign up to request clarification or add additional context in comments.

4 Comments

Thanks, that one works fine. I tried to use the same loading method for the "places" but in vain, still the same error.
can u post your Place Autocomplete Address Form
that would be quite complicated to send extract of my own code, things are here and there to suit my navigation system and that is why I wish to load dynamically, but the whole thing does work when I hard include the google js on my main page using <script>. The complete code is under developers.google.com/maps/documentation/javascript/examples/…
It does help, just not sure of what my initialise() function should look like

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.