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?

alogg.net
  • 21
  • 4
  • do u have firebug installed in firefox? – Dave Apr 20 '14 at 07:08
  • no I don't, the console returns that on firefox "A call to document.write() from an asynchronously-loaded external script was ignored." – alogg.net Apr 20 '14 at 07:10
  • I just ran your code and it was loaded successfully for me. I included jquery 1.10.1. – Dave Apr 20 '14 at 07: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 – alogg.net Apr 20 '14 at 07:45

1 Answers1

0

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

.
Dave
  • 4,376
  • 3
  • 24
  • 37
  • Thanks, that one works fine. I tried to use the same loading method for the "places" but in vain, still the same error. – alogg.net Apr 20 '14 at 08:02
  • can u post your Place Autocomplete Address Form – Dave Apr 20 '14 at 08:08
  • 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 – alogg.net Apr 20 '14 at 08:24
  • It does help, just not sure of what my initialise() function should look like – alogg.net Apr 20 '14 at 08:38