?? clocationexamplelocationengine.cpp
字號:
/*
* ============================================================================
* Name : CLocationExampleLocationEngine.cpp
* Part of : Location Example
* Created : 21.05.2007 by Forum Nokia
* Description:
* Version : 1.0
* Copyright: Nokia Corporation
* ============================================================================
*/
// INCLUDE FILES
#include <e32math.h>
#include "clocationexamplelocationengine.h"
// ---------------------------------------------------------
// CLocationExampleLocationEngine::NewL()
// ---------------------------------------------------------
//
CLocationExampleLocationEngine* CLocationExampleLocationEngine::NewL()
{
CLocationExampleLocationEngine* self = NewLC();
CleanupStack::Pop(self);
return self;
}
// ---------------------------------------------------------
// CLocationExampleLocationEngine::NewLC()
// ---------------------------------------------------------
//
CLocationExampleLocationEngine* CLocationExampleLocationEngine::NewLC()
{
CLocationExampleLocationEngine* self = new (ELeave) CLocationExampleLocationEngine();
CleanupStack::PushL(self);
self->ConstructL();
return self;
}
// ---------------------------------------------------------
// CLocationExampleLocationEngine::ConstructL()
// ---------------------------------------------------------
//
void CLocationExampleLocationEngine::ConstructL()
{
}
// ---------------------------------------------------------
// CLocationExampleLocationEngine::CLocationExampleLocationEngine()
// ---------------------------------------------------------
//
CLocationExampleLocationEngine::CLocationExampleLocationEngine()
{
}
// ---------------------------------------------------------
// CLocationExampleLocationEngine::~CLocationExampleLocationEngine()
// ---------------------------------------------------------
//
CLocationExampleLocationEngine::~CLocationExampleLocationEngine()
{
}
// ---------------------------------------------------------
// CLocationExampleLocationEngine::CalculateDistance()
// ---------------------------------------------------------
//
TReal CLocationExampleLocationEngine::CalculateDistanceL(const TCoordinate& aFrom, const TCoordinate& aTo)
{
TReal result = 0;
TReal val1 = 0;
TReal val2 = 0;
Math::Cos(val1,aFrom.Latitude()*KDectorad);
Math::Cos(val2,aFrom.Longitude()*KDectorad);
TReal aVal = val1 * val2;
Math::Cos(val1,aTo.Latitude()*KDectorad);
Math::Cos(val2,aTo.Longitude()*KDectorad);
TReal bVal = val1 * val2;
Math::Cos(val1,aFrom.Latitude()*KDectorad);
Math::Sin(val2,aFrom.Longitude()*KDectorad);
TReal cVal = val1 * val2;
Math::Cos(val1,aTo.Latitude()*KDectorad);
Math::Sin(val2,aTo.Longitude()*KDectorad);
TReal dVal = val1 * val2;
Math::Sin(val1,aFrom.Latitude()*KDectorad);
Math::Sin(val2,aTo.Latitude()*KDectorad);
TReal eVal = val1 * val2;
TInt err = Math::ACos(result, (aVal*bVal) + cVal*dVal + eVal);
User::LeaveIfError(err);
result = result * KEarthRadius;
return result;
}
// ---------------------------------------------------------
// CLocationExampleLocationEngine::GetDirectionL()
// Notice, that if you have two points laying at the same
// latitude than doesn't mean that bearing always be strict
// W or E (it will be so only if the latitude is 0), but
// if two points at the same longitude than bearing always
// be strict N or S
// ---------------------------------------------------------
//
TDesC& CLocationExampleLocationEngine::GetDirection(const TCoordinate& aFrom, const TCoordinate& aTo)
{
iDirection.Zero();
TReal bearing;
TReal from_lat,from_long,to_lat, to_long;
TReal sin_a_lat, sin_b_lat, cos_a_lat, cos_b_lat, sin_dlon, cos_dlon;
// Temp variables
from_lat = aFrom.Latitude();
from_long = aFrom.Longitude();
to_lat = aTo.Latitude();
to_long = aTo.Longitude();
Math::Sin(sin_dlon, KDectorad*(to_long-from_long));
Math::Cos(cos_b_lat, KDectorad*to_lat);
Math::Sin(sin_a_lat, KDectorad*from_lat);
Math::Sin(sin_b_lat, KDectorad*to_lat);
Math::Cos(cos_a_lat, KDectorad*from_lat);
Math::Cos(cos_b_lat, KDectorad*to_lat);
Math::Cos(cos_dlon, KDectorad*(to_long-from_long));
Math::ATan(bearing, sin_dlon*cos_b_lat, cos_a_lat*sin_b_lat-sin_a_lat*cos_b_lat*cos_dlon);
// Add labels to iDirection based on bearing (-pi < bearing <= pi)
TReal b2mod;
// Make bearing positive and shifted by pi/8, so we can easy find label by dividing
// shifted bearing by pi/4
// e.g. N (-pi/8; pi/8) -> (0; pi/4)
Math::Mod(b2mod, bearing+(2+0.125)*KPi, 2*KPi);
TInt16 segment;
Math::Int(segment, b2mod/(KPi/4));
switch(segment)
{
case 0:
iDirection.Append(KNorth);break;
case 1:
iDirection.Append(KNorthEast);break;
case 2:
iDirection.Append(KEast);break;
case 3:
iDirection.Append(KSouthEast);break;
case 4:
iDirection.Append(KSouth);break;
case 5:
iDirection.Append(KSouthWest);break;
case 6:
iDirection.Append(KWest);break;
case 7:
iDirection.Append(KNorthWest);break;
default:
iDirection.Append(KInvalidDirection);break;
}
return iDirection;
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -