GetLocation()

Description:

The GetLocation method retrieves the current location of the device.

This method can be called both synchronously and asynchronously.

Syntax:

For synchronous calls:

GetLocation(parameters:Object):Object

For asynchronous calls:

GetLocation(parameters:Object, callback:Object):Object

Arguments:

  • parameters:

    This is an object that specifies what type of device location information is returned and how. For more information about the object properties and how to define them, see section Parameters for retrieving location information.

  • callback:

    The callback argument is the name of the method that is executed when an asynchronous GetLocation call has results or status information to return. You must define this method separately. Follow the instructions in section Defining the callback handler for an asynchronous method to define the callback method.

    This argument is used only with an asynchronous GetLocation call.

Return value:

If synchronous, the GetLocation method returns an object that contains the requested location information, an error code, and an error message.

Table: Return value properties for a synchronous GetLocation

Property

Description

Value

ReturnValue

This is an object that contains the requested location information.

See Returned location information.

ErrorCode

This is a number that specifies a predefined error code.

See Service API error codes.

ErrorMessage

This is a text string that describes the error.

If asynchronous, the GetLocation method returns an object that contains the initial return value for the asynchronous call it started (see the following table). The actual location information is returned by the callback method in the ReturnValue property of its result object. The returned information is described in section Returned location information.

Table: Return value properties for an asynchronous GetLocation

Property

Description

Value

TransactionID

This is a number used as an identification to match transactions started with the asynchronous GetLocation call to one or more calls it generates to callback.

 

ErrorCode

This is a number that specifies a predefined error code.

See Service API error codes.

ErrorMessage

This is a text string that describes the error.

Remarks:

  • The availability of specific location information depends on the underlying GPS technology. Other factors, such as the number of satellites available for a location fix, also affect what information can be returned. You can change the positioning system used by an S60 device from the Settings > General > Positioning > Positioning methods menu.

  • It takes time to retrieve the initial position fix. Subsequent requests are faster.

Example code:

The following sample code illustrates how to retrieve all details of the specific location information using GetList synchronously:

import com.nokia.lib.Service;
var location = new Service("Service.Location", "ILocation");
var inParams = {LocationInformationClass:"GenericLocationInfo"};
var outParams = location.GetLocation(inParams);
if (outParams.ErrorCode == 0) {
  var outList = outParams.ReturnValue;
  var longitude = outList.Longitude;// Contains longitudinal data
  var latitude = outList.Latitude;// Contains latitudinal data
} else {
  var errorId = outParam.ErrorCode;
}

The following sample code illustrates how to retrieve all details of the specific location information using GetList asynchronously:

import com.nokia.lib.Service;
var location = new Service("Service.Location", "ILocation");
var inParams = {LocationInformationClass:"GenericLocationInfo"};
location.GetLocation(inParams,onReceive);
function onReceive (transactionID:Number, eventID:String, outParam:Object) {
  if (outParam.ErrorCode == 0) {
    var outList = outParam.ReturnValue;
    var longitude = outList.Longitude;// Contains longitudinal data
    var latitude = outList.Latitude;// Contains latitudinal data
    
  } else {
    var errorId = outParam.ErrorCode;
  }
}