getCurrentPosition Method

Use this command to get the current location of the device.

intel.xdk.geolocation.getCurrentPosition(successFunction,errorFunction);

Description:

Use this command to get the current location. This command asynchronously acquires the approximate 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.

Example:


var getLocation = function() 
{
    var suc = function(p){
        alert("geolocation success");
        if (p.coords.latitude != undefined)
        {
            currentLatitude = p.coords.latitude;
            currentLongitude = p.coords.longitude;
        }

    };
    var fail = function(){ 
        alert("geolocation failed"); 
        getLocation();
    };

    intel.xdk.geolocation.getCurrentPosition(suc,fail);
}
            
Para obtener información más completa sobre las optimizaciones del compilador, consulte nuestro Aviso de optimización.