Catching Google Maps error when starting app while offline

1,402 views
Skip to first unread message

Florian

unread,
Apr 14, 2012, 3:10:50 AM4/14/12
to Google Maps JavaScript API v3
Hello everyone,

I have integrated Google Maps Api 3 in my app (Sencha Touch) but when
I'm offline (having no internet connection) and start the app the
following error is thrown:
file:///android_asset/www/app/views/map/MapView.js: Line 144 :
Uncaught ReferenceError: google is not defined
o 04-13 21:48:12.234: E/Web Console(1369): Uncaught ReferenceError:
google is not defined at file:///android_asset/www/app/views/map/MapView.js:144

Actually I just wanna catch this error so that the whole app doenst
stop. But I'm not sure how, since the Google Maps Code is already used
in my index.html file:
<script type="text/javascript" src="http://maps.google.com/maps/api/js?
sensor=true"></script>

Any tips or advices how/where to wrap an try&catch statement?

Thanks in advance,
Florian

Sean Mickey

unread,
Apr 16, 2012, 10:07:33 AM4/16/12
to Google Maps JavaScript API v3
You can check for the existence of google.maps as a way to see if the
Google Maps library has been loaded, even before the exception is
thrown and handle the situation right at the beginning. So rather than
a full try-catch, you could do something like this:

if ( google.maps == undefined ) { /* run the non-connected code */ }
else { /* run the connected code */ }
Reply all
Reply to author
Forward
0 new messages