Calculate()

Description:

The Calculate method performs mathematical calculations based on a source location and a target location.

This is a synchronous method.

Syntax:

Calculate(parameters:Object):Object

Arguments:

  • parameters:

    This is an object that specifies the mathematical operation to perform and the input values to use in the operation. For more information about the object properties and how to define them, see section Calculation parameters.

Return value:

The Calculate method returns an object that contains the calculation results, an error code, and an error message.

Table: Return value properties for Calculate

Property

Description

Value

ReturnValue

This contains the results for the requested mathematical operation. The type of the value depends on the operation.

See Calculation results.

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 WGS 84 datum is used to reference coordinates.

Example code:

The following sample code illustrates how to calculate the distance between specified locations:

import com.nokia.lib.Service;
var location = new Service("Service.Location", "ILocation");
var sourceDistance = {Longitude:1, Latitude:0.49, Altitude:0.5};
var destinationDistance = {Longitude:1, Latitude:0.5, Altitude:0.5};
var inParams = {MathRequest:"FindDistance", DistanceParamSource:sourceDistance, DistanceParamDestination:destinationDistance};
var outParams = location.Calculate(inParams);
if (outParams.ErrorCode == 0) {
  var distance = outParams.ReturnValue;
} else {
  var errorId = outParam.ErrorCode;
}