2

I've tried the following in a number of 2.x android devices with phonegap version 2.0.0:

var onSuccess = function(position){
    console.log("Success");
}
var onError = function(error){
    console.log("Error");
}

gpsTrackWatchID = navigator.geolocation.watchPosition(
    onSuccess,
    onError,
    {
        enableHighAccuracy: true,
        maximumAge: 5000,
        timeout: 10000,
    }
);

If I use the device indoors where there is no GPS signal onError is never called. The documentation states:

If the geolocationSuccess callback is not invoked within this time, the geolocationError callback will be invoked with a PositionError.TIMEOUT error code.

I've tried debugging this by putting a console.log in the watchPosition function in cordova.js, but the function seems never to be getting called. I wonder if the browser's native function is being executed instead of phonegap's?

4

1 回答 1

0

First thing First, Do You set persmission in AndroidManifest correctly? Could You post the file here - especially the persission section?

Secondly, do You use Android 2.3.3 - if Yes, then You must use SDK with Google Maps APi as in normal API GPS location provider don't work.

Ant the last, do You have any JS errors on console, when registering for GPS location?

于 2012-09-17T10:00:34.930 回答