×
Namespaces

Variants
Actions
(Difference between revisions)

Getting position data from TPositionInfoBase

From Nokia Developer Wiki
Jump to: navigation, search
hamishwillee (Talk | contribs)
hamishwillee (Talk | contribs)
m (Hamishwillee - Bot update - Merge KB into wiki)
Line 1: Line 1:
 
[[Category:Location]][[Category:Symbian C++]]
 
[[Category:Location]][[Category:Symbian C++]]
__NOTOC__
+
{{ArticleMetaData <!-- v1.2 -->
__NOEDITSECTION__
+
{{KBCS}}
+
{{ArticleMetaData
+
|id=CS001412
+
|platform=S60 3rd Edition <br>S60 5th Edition
+
|devices=Nokia 5800 XpressMusic
+
|category=Symbian C++
+
|subcategory=Location
+
|creationdate=June 9, 2009
+
|keywords=TPositionInfoBase, TPosition
+
 
+
 
|sourcecode= <!-- Link to example source code (e.g. [[Media:The Code Example ZIP.zip]]) -->
 
|sourcecode= <!-- Link to example source code (e.g. [[Media:The Code Example ZIP.zip]]) -->
 
|installfile= <!-- Link to installation file (e.g. [[Media:The Installation File.sis]]) -->
 
|installfile= <!-- Link to installation file (e.g. [[Media:The Installation File.sis]]) -->
|sdk=<!-- SDK(s) built and tested against (e.g. [http://linktosdkdownload/ Nokia Qt SDK 1.1]) -->
+
|devices= Nokia 5800 XpressMusic
|devicecompatability=<!-- Compatible devices (e.g.: All* (must have GPS) ) -->
+
|sdk= <!-- SDK(s) built and tested against (e.g. [http://linktosdkdownload/ Nokia Qt SDK 1.1]) -->
|signing=<!-- Empty or one of Self-Signed, DevCert, Manufacturer -->
+
|platform= S60 3rd Edition <br>S60 5th Edition
|capabilities=<!-- Capabilities required (e.g. Location, NetworkServices.) -->
+
|devicecompatability= <!-- Compatible devices (e.g.: All* (must have GPS) ) -->
|author=[[User:Tepaa]]
+
|dependencies= <!-- Any other/external dependencies e.g.: Google Maps Api v1.0 -->
 +
|signing= <!-- Empty or one of Self-Signed, DevCert, Manufacturer -->
 +
|capabilities= <!-- Capabilities required by the article/code example (e.g. Location, NetworkServices. -->
 +
|keywords= TPositionInfoBase, TPosition
 +
|language= <!-- Language category code for non-English topics - e.g. Lang-Chinese -->
 +
|translated-by= <!-- [[User:XXXX]] -->
 +
|translated-from-title= <!-- Title only -->
 +
|translated-from-id= <!-- Id of translated revision -->
 +
|review-by= <!-- After re-review: [[User:username]] -->
 +
|review-timestamp= <!-- After re-review: YYYYMMDD -->
 +
|update-by= <!-- After significant update: [[User:username]]-->
 +
|update-timestamp= <!-- After significant update: YYYYMMDD -->
 +
|creationdate= 20090506
 +
|author= [[User:Tepaa]]
 +
<!-- The following are not in current metadata -->
 +
|subcategory= Location
 +
|id= CS001412
 
}}
 
}}
  
 
==Overview==
 
==Overview==
  
This snippet demonstrates two ways of using <tt>TPositionInfoBase</tt>:
+
This snippet demonstrates two ways of using {{Icode|TPositionInfoBase}}:
  
* getting the <tt>TPosition</tt> class from <tt>TPositionInfoBase</tt>
+
* getting the {{Icode|TPosition}} class from {{Icode|TPositionInfoBase}}
* showing <tt>TPosition</tt> in textual format
+
* showing {{Icode|TPosition}} in textual format
  
  
Line 36: Line 41:
 
The following libraries and capabilities are required:
 
The following libraries and capabilities are required:
 
<code>
 
<code>
CAPABILITY     Location
+
CAPABILITY Location
LIBRARY       lbs.lib
+
LIBRARY lbs.lib
 
</code>
 
</code>
  
Line 175: Line 180:
 
==Postconditions==
 
==Postconditions==
  
Position data is read from <tt>TPositionInfoBase</tt>.
+
Position data is read from {{Icode|TPositionInfoBase}}.
  
  
 
==See also==
 
==See also==
  
* [[CS001376 - Retrieving GPS location]]
+
* [[CS001411 - Retrieving location information]]
 
* [http://www.developer.nokia.com/info/sw.nokia.com/id/b8bf64b5-97b0-48bc-9ea2-8f20430c34c0/S60_Platform_Location_Example.html S60 Platform Location Example]
 
* [http://www.developer.nokia.com/info/sw.nokia.com/id/b8bf64b5-97b0-48bc-9ea2-8f20430c34c0/S60_Platform_Location_Example.html S60 Platform Location Example]
 
   
 
   
  
  
[[Category:Code Examples]]
+
[[Category:Code Snippet]]
 
[[Category:Code Snippet]]
 
[[Category:Code Snippet]]

Revision as of 09:57, 13 June 2012

Article Metadata
Tested with
Devices(s): Nokia 5800 XpressMusic
CompatibilityArticle
Keywords: TPositionInfoBase, TPosition
Created: tepaa (06 May 2009)
Last edited: hamishwillee (13 Jun 2012)

Contents

Overview

This snippet demonstrates two ways of using TPositionInfoBase:

  • getting the TPosition class from TPositionInfoBase
  • showing TPosition in textual format


Note: The Location capability is included in the self-signing capabilities of S60 3rd Edition, Feature Pack 2 and newer platforms.


MMP file

The following libraries and capabilities are required:

CAPABILITY Location
LIBRARY lbs.lib


Header

#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;


Source

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);
}
}


Postconditions

Position data is read from TPositionInfoBase.


See also

138 page views in the last 30 days.
×