chakradharmantha / jquery-ui-map

Automatically exported from code.google.com/p/jquery-ui-map
0 stars 0 forks source link

google is 'undefined' error when Google API is not loaded #54

Open GoogleCodeExporter opened 8 years ago

GoogleCodeExporter commented 8 years ago
What steps will reproduce the problem?
1. Plug-in code assumes that google API is always loaded, and throws google is 
'undefined' error, when the API is not loaded because of some network issue

What is the expected output? What do you see instead?
Error on line 340 saying google maps is undefined. If you change from:
  if ( google.maps && this[0] instanceof google.maps.MVCObject ) {
to:
  if ( (typeof (google) !== 'undefined') && google.maps && this[0] instanceof google.maps.MVCObject ) {
everything works fine.

What version of the product are you using? On what operating system?
3.0-rc on Windows XP

Original issue reported on code.google.com by raksha.a...@gmail.com on 25 Jun 2012 at 6:57

GoogleCodeExporter commented 8 years ago
I am still using ui-map 2.0 and trying to load google.maps dynamically due to 
network connection on mobile device is not always available. 

I try to load jquery-ui-map-2.0.js dynamically  in  the callback of finishing 
loading google map api js.   But it gets script error when calling: 
$('#map_canvas').gmap( {'center' : '12.34, 56.334'} );

Below are code snippets: 

function addScriptToHead( stSrc) {
  var s = document.createElement("script");
  s.type = "text/javascript";
  s.src = stSrc;
  // Use any selector
  $("head").append(s);   
}

....
    addScriptToHead( "http://maps.google.com/maps/api/js?sensor=false&callback=googlemaps_init"); //2012.12.18 works and  googlemaps_init() is called.      

function googlemaps_init(){  
  //2012.12.19 now it is safe to load ui-map widget.
  addScriptToHead( "jquery.mobile/jquery.ui.map-2.0.min.js" ); //2012.12.18 load it after gmap

}

--- after all above is executed. calling the following and get error
$('#map_canvas').gmap({ 'center': '-31.952,115.857' });

Original comment by george.g...@gmail.com on 19 Dec 2012 at 3:27

GoogleCodeExporter commented 8 years ago
This script shouldn't fail if Google Maps it's not loaded.
Changing

 if ( google.maps && this[0] instanceof google.maps.MVCObject ) {

to

 if ( typeof("google") != 'undefined' && google.maps && this[0] instanceof google.maps.MVCObject ) {

In 
http://code.google.com/p/jquery-ui-map/source/browse/trunk/ui/jquery.ui.map.js#3
38

and

http://code.google.com/p/jquery-ui-map/source/browse/trunk/ui/jquery.ui.map.js#3
51

fies this.

Original comment by martin.s...@gmail.com on 16 Jun 2014 at 2:40