【发布时间】:2015-05-18 11:01:19
【问题描述】:
我正在使用 phonegap 应用程序中的地理定位。当高精度和省电模式打开时,我很容易获得位置。但是在 GPS 中工作时会出错。请帮忙。我被困在里面了。
我将超时设置为 60000 毫秒。但即使在那时也没有用。
代码是-
function Geolocation(){}
Geolocation.options = {
maximumAge: 60000,
timeout: 15000,
enableHighAccuracy: true
};
Geolocation.errorMessage = 'Unable to get location data. Ensure that the location services are enabled in high accuracy mode. If enabled, try turning off/on location services and open this page again';
Geolocation.update = function() {
navigator.geolocation.getCurrentPosition(Geolocation.updateSuccess, Geolocation.highAccuracyError, Geolocation.options);
}
Geolocation.highAccuracyError = function(err) {
if (err.code == 3) {
var options = Geolocation.options;
options.enableHighAccuracy = false;
options.timeout = 15000;
navigator.geolocation.getCurrentPosition(Geolocation.updateSuccess, Geolocation.lowAccuracyError, options);
}
}
Geolocation.lowAccuracyError = function(err) {
Geolocation.currentLocation = null;
}
Geolocation.updateSuccess = function(position) {
Geolocation.currentLocation = {};
Geolocation.currentLocation.latitude = position.coords.latitude;
Geolocation.currentLocation.longitude = position.coords.longitude;
}
提前致谢
【问题讨论】:
-
您遇到的错误是什么?
-
当我打开 GPS 而不是高精度或省电模式时,只会出现低精度错误。简而言之,如果只有 GPS 开启,即使 1 分钟后我也无法获得位置
-
您的手机完全有可能无法仅根据 GPS 硬件获取其位置。例如,如果您在地下,您的手机将无法连接到 GPS 卫星。而且你不需要在地下就可以做到这一点。根据您所说,我认为 Cordova 正确地向您报告手机无法确定其位置。
标签: cordova gps geolocation