2017-03-17 90 views
1

我正在开发一个应用程序,使用Ionic v2,Google Maps API v3和Cordova Geolocation来跟踪用户的位置。Ionic 2和Cordova Geolocation之间的集成

问题: 当我在GPS关闭的Android设备上运行应用程序时,我总是收到“代码3:超时过期”错误。

我的问题是:

  1. 如若科尔多瓦地理位置使用电话网络(或WiFi)来获得用户位置时,GPS离线?
  2. 如果没有,还有另一种方法可以使用网络或Wifi找到用户位置?

我的代码:

getCurrentPosition (callback: (result: any) => any) { 
    Geolocation.getCurrentPosition({timeout: 5000}).then((resp) => { 
     console.log('Getting location:'); 
     console.log('Lat ' + resp.coords.latitude); 
     console.log('Lng ' + resp.coords.longitude); 
     callback(resp.coords); // send the results to the 
    }).catch((error) => { 
     alert('Error getting location'+JSON.stringify(error)); 
     alert(' Code: '+ error.code + ' Message: ' +error.message); 
    }); 
    } 

最佳,

回答

0

如果位置被关闭,该应用程序不能访问的位置,GPS或网络。这是一个安全/隐私设置。您可以使用Diagnostic插件来查找是否打开位置并提示用户打开它。检查出docs.