地理定位不适用于 GPS 关闭

Geolocation doesn't work with GPS off

我正在使用 htlm5 和 javascript 使用 phonegap 构建服务编写移动应用程序。 我尝试获取地理位置,但如果我的智能手机上的 GPS 关闭,它就不起作用。我在大约 30 秒后收到 alert("Sorry, no position available.") 警报。 如果我打开 gps,我就能得到地理定位。 我试过 getCurrentPositionwatchPosition 都不适合我。 我的代码:

document.addEventListener("deviceready", onDeviceReady, false);

var geo_options = {
    enableHighAccuracy : true,
    maximumAge : 30000,
    timeout : 27000
};

function onDeviceReady() {
    // navigator.geolocation.getCurrentPosition(geo_success, geo_error, geo_options);
    navigator.geolocation.watchPosition(geo_success, geo_error, geo_options);
}

function geo_success(position) {
    alert(position.coords.latitude+" "+position.coords.longitude);
}

function geo_error() {
    alert("Sorry, no position available.");
}

当智能手机上的 GPS 关闭时,如何获取地理位置?

您可以检查使用地理定位是否可用,以便您可以处理这两种情况:

if (navigator.geolocation) {
// get location
} else {
// handle no geolocation
}