Symbian
Symbian Developer Library

SYMBIAN OS V9.4

Feedback

[Index] [Previous] [Next]


How to use LBS maths functions

[Top]


Purpose

This document describes how to use LBS maths functions to calculate distances, bearings, speeds and to perform coordinate translations. Developers can use either the LBS position data classes or the maths class TPositionCalc to perform calculations.

[Top]


Required background

Familiarity with Position info and data classes and LBS maths functions is required.

[Top]


Using the LBS position data classes

Using the position data class maths functions is equivalent to using the TPositionCalc functions as described below.

Applications must include LbsPosition.h and link against LbsSelfLocate.lib.

The code examples illustrate how to call the maths functions. In a real application, the device location would be obtained through the Location Acquisition API.

Calculating the distance between two points

#include <LbsPosition.h>

TInt err;
TReal32 distance;
TReal32 accuracy;

// Define two coordinates
TCoordinate coor1(51.88, 0.45);
TCoordinate coor2(52.69, 0.30);
 
// Calculate distance using TCoordinate objects
err = coor1.Distance(coor2, distance);
if (err != KErrNone)
 {
 // Handle error
 ...
 }
// distance now contains the distance between coor1 and coor2 

// Calculate distance using TLocality objects with a horizontal accuracy of 10 metres...
TLocality loc1(coor1, 10);
TLocality loc2(coor2, 10);
 
err = loc1.Distance(loc2, distance, accuracy);
if (err != KErrNone)
 {
 // Handle error
 ...
 }
// distance now contains distance between loc1 and loc2 
// accuracy now contains the possible error in the distance calculation (in metres)

Calculating a bearing

...

TReal32 bearing;
  
// Calculate bearing Using TCoordinate objects...
err = coor1.BearingTo(coor2, bearing);
if (err != KErrNone)
{
 // Handle error
}
// bearing now contains the calculated bearing from coor1 to coor2
  
// Calculate bearing using TLocality objects...
err = loc1.BearingTo(loc2, bearing, accuracy);
if (err != KErrNone)
 {
 // Handle error
 }
// accuracy now contains the possible error in the bearing calculation (in degrees)

Calculating a speed

/
...

TReal32 speed;

// Calculate speed using TPosition objects...
 
// Example time values 1 second apart...
TTime time1(1000000);
TTime time2(2000000);

TPosition pos1(loc1, time1);
TPosition pos2(loc2, time2);
 
// Calculate average speed between pos1 and pos2
err = pos1.Speed(pos2, speed);
if (err != KErrNone)
{
// Handle error
}
// speed now contains the average speed

// Calculate speed using TLocality objects...
err = pos1.Speed(pos2, speed, accuracy);
if (err != KErrNone)
{
 // Handle error
}
// accuracy contains possible error in the speed calculation (in metres per second)
 

Translating a position

... 

// Translate coor1 50 metres along 60 degree bearing
err = coor1.Move(60, 50);
if (err != KErrNone)
{
// Handle error
}
// finalPos1 is the calculated translated position

[Top]


Using TPositionCalc

Using the TPositionCalc maths functions is equivalent to using the position data functions as described above.

Applications must include LbsPosition.h and LBSPositionCalc.h and link against LbsSelfLocate.lib.

Calculating the distance between two points

#include <LbsPosition.h>
#include <LbsPositionCalc.h>

TInt err;
TReal32 distance;
TReal32 accuracy;
 
TCoordinate coor1(51.88, 0.45);
TCoordinate coor2(52.69, 0.30);
 
// Calculate distance using TCoordinate objects
err = TPositionCalc::GetDistance(coor1, coor2, distance);
if (err != KErrNone)
{
// Handle error
}
 
// Calculate distance using TLocality objects with a horizontal accuracy of 10 metres...
TLocality loc1(coor1, 10);
TLocality loc2(coor2, 10);
 
err = TPositionCalc::GetDistance(loc1, loc2, distance, accuracy);
if (err != KErrNone)
{
// Handle error
}
// distance now contains distance between loc1 and loc2 
// accuracy now contains the possible error in the distance calculation (in metres)

Calculating a bearing

...

TReal32 bearing;
  
// Calculate bearing Using TCoordinate objects...
err = TPositionCalc::GetBearing(coor1, coor2, bearing);
if (err != KErrNone)
{
// Handle error
}
// bearing now contains the calculated bearing from coor1 to coor2

// Calculate bearing using TLocality objects...
err = TPositionCalc::GetBearing(loc1, loc2, bearing, accuracy);
{
// Handle error
}
// accuracy now contains the possible error in the bearing calculation (in degrees)

Calculating a speed

 
...

TReal32 speed;
      
// Using TPosition objects...
 
// Example time values 1 second apart...
TTime time1(1000000);
TTime time2(2000000);

TPosition pos1(loc1, time1);
TPosition pos2(loc2, time2);

// Calculate average speed between pos1 and pos2
err = TPositionCalc::GetSpeed(pos1, pos2, speed);
if (err != KErrNone)
{
// Handle error
}
// speed now contains the average speed

// Calculate speed using TLocality objects...  
err = TPositionCalc::GetSpeed(pos1, pos2, speed, accuracy);
if (err != KErrNone)
{
// Handle error
}
// accuracy contains possible error in the speed calculation (in metres per second)

Translating a position

...

// Translate coor1 50 metres on a bearing of 60 degrees

TReal distance = 50;
TReal bearing = 60;

TCoordinate translatedCoor1;
err = TPositionCalc::Translate(coor1, distance, bearing, translatedCoor1);
if (err != KErrNone)
{
// Handle error
}

// translatedCoor1 is the translated coordinate

[Top]


See also

LBS maths functions

Position info and data classes