×
Namespaces

Variants
Actions
Revision as of 09:39, 24 August 2012 by hamishwillee (Talk | contribs)

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

从TPositionInfoBase获得位置数据

From Nokia Developer Wiki
Jump to: navigation, search
Article Metadata

兼容于
平台安全性
能力: Location

文章
翻译:
hoolee
最后由 hamishwillee 在 24 Aug 2012 编辑
  • 详细描述

下列代码片段为使用TPositionInfoBase的两步方法:

  1. 从TPositionInfoBase获得TPosition类
  2. 用文本格式显示TPosition

注意:S60第三版FP2及后继版本的自签名程序拥有定位能力。


  • MMP文件

需要下列链接库和能力

CAPABILITY Location
LIBRARY lbs.lib
  • 头文件
#include <LbsPositionInfo.h> 
#include <LbsPosition.h>
 
// Degrees sign delimeter used in formatting methods
_LIT(KDelimDegree,"\xb0"); // "°" symbol
 
// Dot delimeter used in formatting methods
_LIT(KDelimDot,"\x2e"); // "." symbol
 
// Plus sign delimeter used in formatting methods
_LIT(KDelimPlus,"\x2b"); // "+" symbol
 
// Minus sign delimeter used in formatting methods
_LIT(KDelimMinus,"\x2d"); // "-" symbol
 
// Quotation sign delimeter used in formatting methods
_LIT(KDelimQuot,"\x22"); // "\"" symbol
 
// Apostrophe sign delimeter used in formatting methods
_LIT(KApostrophe,"\x27"); // "'" symbol
 
const TInt KDegreeLength = 19;
  • 源文件
void CMyClass::PositionUpdated(TPositionInfoBase& aPosInfo)
{
// Check if position information class type is TPositionInfo
if (aPosInfo.PositionClassType() & EPositionInfoClass)
{
// Cast the TPositionInfoBase object to TPositionInfo
TPositionInfo* posInfo = static_cast<TPositionInfo*>(&aPosInfo);
 
// Get position
TPosition position;
posInfo->GetPosition(position);
 
// Convert positions to the descriptors
TBuf<KDegreeLength> latitudeDegr;
GetDegreesString(position.Latitude(), latitudeDegr);
 
// Convert positions to the descriptors
TBuf<KDegreeLength> longitudeDegr;
GetDegreesString(position.Longitude(), longitudeDegr);
}
}
void CMyClass::GetDegreesString(
const TReal64& aDegrees,TBuf<KDegreeLength>& aDegreesString) const
{
const TReal KSecondsInMinute = 60.0;
const TInt KNumWidth = 3;
 
// If the aDegree is a proper number
if ( !Math::IsNaN(aDegrees) )
{
// Integer part of the degrees
TInt intDegrees = static_cast<TInt>(aDegrees);
 
// Positive float of the degrees
TReal64 realDegrees = aDegrees;
 
// Convert to positive values
if ( intDegrees < 0 )
{
intDegrees = -intDegrees;
realDegrees = -realDegrees;
}
 
// Minutes
TReal64 realMinutes = (realDegrees - intDegrees) * KSecondsInMinute;
 
// Integer part of the minutes
TInt intMinutes = static_cast<TInt>(realMinutes);
 
// Seconds
TReal64 realSeconds = (realMinutes - intMinutes) * KSecondsInMinute;
TInt intSeconds = static_cast<TInt>((realMinutes - intMinutes) * KSecondsInMinute);
 
// Check the sign of the result
if ( aDegrees >= 0 )
{
aDegreesString.Append(KDelimPlus);
}
else
{
aDegreesString.Append(KDelimMinus);
}
 
// Add the degrees
TInt64 value = intDegrees;
aDegreesString.AppendNum(value);
 
// Add the separator
aDegreesString.Append(KDelimDegree);
 
// Add the minutes
value = intMinutes;
aDegreesString.AppendNum(value);
 
// Add the separator
aDegreesString.Append(KApostrophe);
 
// Add the seconds
value = intSeconds;
aDegreesString.AppendNum(value);
 
// Add the separator
aDegreesString.Append(KDelimQuot);
 
// Add the separator
aDegreesString.Append(KDelimDot);
 
// Get six last digits
realSeconds -= intSeconds;
realSeconds *= 1000;
 
// Add the seconds
aDegreesString.AppendNumFixedWidth(static_cast<TInt>(realSeconds),
EDecimal, KNumWidth);
}
}
  • 后记

读取并显示了TPositionInfoBase的位置数据

  • 参考连接

Retrieving location information using Symbian C++

S60 Platform Location Example

This page was last modified on 24 August 2012, at 09:39.
59 page views in the last 30 days.