watchPosition Method

Use this command rather than the getCurrentLocation command to track progress during a trip rather than just getting a single position.

var watchTimer = intel.xdk.geolocation.watchPosition(successFunction,errorFunction,options);

Description:

Use this command rather than the getCurrentLocation command to track progress during a trip rather than just getting a single position. This command asynchronously acquires the latitude and longitude of the device. When data is available, the success function is called. If there is an error getting position data, the error function is called.

Available Platforms:

Parameters:

  • successFunction: When data is available, this success function is called.
  • errorFunction: If there is an error getting position data, the error function is called.
  • options: Some options may be specified for the method as an array object.


Option Possible Values Use
timeout (an integer) The number of milliseconds between checks of position rather than the default value of 10000 (or ten seconds).
enableHighAccuracy True This will force the command to report back a more accurate latitude and longitude position at the expense of more battery usage.
maximumAge (an integer) The number of milliseconds the command will wait before deciding that it cannot get a new position reading and instead run the error message.

Example:


//This array holds the options for the command
var options = {timeout: 10000, maximumAge: 11000, enableHighAccuracy: true };

//This function is called on every iteration of the watch Position command that fails
var fail = function(){
  alert("Geolocation failed. \nPlease enable GPS in Settings.");
};

//This function is called on every iteration of the watchPosition command that is a success
var suc = function(p){
  alert("Moved To: Latitude:" + p.coords.latitude + "Longitude:" + p.coords.longitude);
};

//This command starts watching the geolocation
var geolocationWatchTimer = intel.xdk.geolocation.watchPosition(suc,fail,options);

//Call the stopGeolocation function to stop the geolocation watch
var stopGeolocation = function(){
        intel.xdk.geolocation.clearWatch(geolocationWatchTimer);
}
            
Пожалуйста, обратитесь к странице Уведомление об оптимизации для более подробной информации относительно производительности и оптимизации в программных продуктах компании Intel.