{"action":"created","issue":{"url":"https://api.github.com/repos/angular-ui/angular-google-maps/issues/1520","labels_url":"https://api.github.com/repos/angular-ui/angular-google-maps/issues/1520/labels{/name}","comments_url":"https://api.github.com/repos/angular-ui/angular-google-maps/issues/1520/comments","events_url":"https://api.github.com/repos/angular-ui/angular-google-maps/issues/1520/events","html_url":"https://github.com/angular-ui/angular-google-maps/issues/1520","id":107357294,"number":1520,"title":"online listener is not added on Cordova app","user":{"login":"jabas06","id":3453385,"avatar_url":"https://avatars.githubusercontent.com/u/3453385?v=3","gravatar_id":"","url":"https://api.github.com/users/jabas06","html_url":"https://github.com/jabas06","followers_url":"https://api.github.com/users/jabas06/followers","following_url":"https://api.github.com/users/jabas06/following{/other_user}","gists_url":"https://api.github.com/users/jabas06/gists{/gist_id}","starred_url":"https://api.github.com/users/jabas06/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jabas06/subscriptions","organizations_url":"https://api.github.com/users/jabas06/orgs","repos_url":"https://api.github.com/users/jabas06/repos","events_url":"https://api.github.com/users/jabas06/events{/privacy}","received_events_url":"https://api.github.com/users/jabas06/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":1,"created_at":"2015-09-19T21:36:50Z","updated_at":"2015-10-16T04:14:03Z","closed_at":null,"body":"I've an issue with an ionic app. When the application starts with no network connection, an 'online' event listener is supposed to try to load the gmaps sdk, through uiGmapMapScriptLoader service, but the listener is never created. The problem is that before to create the listener, a safety check for `window.navigator.connection` and `window.Connection` is performed but they are available until `deviceready` event is triggered.\r\n\r\nI fixed it waiting for the deviceready to then check if window.navigator.connection and window.Connection are defined, nevertheless the deviceready event doesn't work on browsers\r\n\r\n```coffeescript\r\n# Cordova specific https://github.com/apache/cordova-plugin-network-information/\r\ndocument.addEventListener 'deviceready', ->\r\n  if window.navigator.connection && window.Connection && window.navigator.connection.type == window.Connection.NONE\r\n    document.addEventListener 'online', ->\r\n      includeScript options if !isGoogleMapsLoaded()\r\n  else\r\n    includeScript options\r\n```\r\n\r\nI'm using 2.2.1 version\r\n"},"comment":{"url":"https://api.github.com/repos/angular-ui/angular-google-maps/issues/comments/148595874","html_url":"https://github.com/angular-ui/angular-google-maps/issues/1520#issuecomment-148595874","issue_url":"https://api.github.com/repos/angular-ui/angular-google-maps/issues/1520","id":148595874,"user":{"login":"jabas06","id":3453385,"avatar_url":"https://avatars.githubusercontent.com/u/3453385?v=3","gravatar_id":"","url":"https://api.github.com/users/jabas06","html_url":"https://github.com/jabas06","followers_url":"https://api.github.com/users/jabas06/followers","following_url":"https://api.github.com/users/jabas06/following{/other_user}","gists_url":"https://api.github.com/users/jabas06/gists{/gist_id}","starred_url":"https://api.github.com/users/jabas06/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jabas06/subscriptions","organizations_url":"https://api.github.com/users/jabas06/orgs","repos_url":"https://api.github.com/users/jabas06/repos","events_url":"https://api.github.com/users/jabas06/events{/privacy}","received_events_url":"https://api.github.com/users/jabas06/received_events","type":"User","site_admin":false},"created_at":"2015-10-16T04:14:03Z","updated_at":"2015-10-16T04:14:03Z","body":"In order to my solution works in browsers, now I wait for window.Load event then I check if the app its within a WebView and in that case I add a listener for the deviceready event.\r\n\r\n```coffeescript\r\nonWindowLoad = (options)->\r\n        # if its a WebView\r\n        if !(!window.cordova && !window.PhoneGap && !window.phonegap && !window.forge)\r\n          document.addEventListener 'deviceready', ->\r\n            # Cordova specific https://github.com/apache/cordova-plugin-network-information/\r\n            if window.navigator.connection && window.Connection && window.navigator.connection.type == window.Connection.NONE\r\n              document.addEventListener 'online', ->\r\n                  if !lastNetworkStatus || lastNetworkStatus != 'online'\r\n                    lastNetworkStatus = 'online';\r\n                    includeScript options if !isGoogleMapsLoaded()\r\n\r\n              document.addEventListener 'offline', ->\r\n                lastNetworkStatus = 'offline';\r\n            else\r\n              includeScript options\r\n\r\n        else\r\n          includeScript options\r\n\r\n      load: (options)->\r\n        deferred = $q.defer()\r\n\r\n        # Early-resolve if google-maps-api is already in global-scope\r\n        if isGoogleMapsLoaded()\r\n          deferred.resolve window.google.maps\r\n          return deferred.promise\r\n\r\n        randomizedFunctionName = options.callback = 'onGoogleMapsReady' + Math.round(Math.random() * 1000)\r\n        window[randomizedFunctionName] = ->\r\n          window[randomizedFunctionName] = null\r\n          deferred.resolve window.google.maps\r\n          return\r\n\r\n        if document.readyState == 'complete'\r\n          onWindowLoad(options)\r\n        else\r\n          window.addEventListener 'load', ->\r\n            window.removeEventListener 'load', onWindowLoad, false\r\n            onWindowLoad(options)\r\n\r\n        # Return the promise\r\n        deferred.promise\r\n```"}}