当应用程序在Phonegap中处于脱机状态时,Google地图会崩溃

时间:2013-11-01 08:04:37

标签: android html5 google-maps cordova

我正在通过Phonegap与谷歌地图集成的项目。

当数据连接不存在时,在浏览器中获取错误页面,如“网页不可用”,如下所示。

enter image description here

有人能帮帮我吗?

1 个答案:

答案 0 :(得分:0)

请尝试检查连接,如果其数据已连接,则可以进行地图呼叫。您也无法在离线时提出任何跨域请求

样品

function checkConnection() {
    var networkState = navigator.connection.type;

    var states = {};
    states[Connection.UNKNOWN]  = 'Unknown connection';
    states[Connection.ETHERNET] = 'Ethernet connection';
    states[Connection.WIFI]     = 'WiFi connection';
    states[Connection.CELL_2G]  = 'Cell 2G connection';
    states[Connection.CELL_3G]  = 'Cell 3G connection';
    states[Connection.CELL_4G]  = 'Cell 4G connection';
    states[Connection.CELL]     = 'Cell generic connection';
    states[Connection.NONE]     = 'No network connection';

    alert('Connection type: ' + states[networkState]);
}

checkConnection();

请参阅phonegap文档更多选项 http://docs.phonegap.com/en/3.1.0/cordova_connection_connection.md.html#Connection