×
Namespaces

Variants
Actions
(Difference between revisions)

Obtaining current device position

From Nokia Developer Wiki
Jump to: navigation, search
Den123 (Talk | contribs)
(New page: Category:Symbian C++ Category:Location Based Services Category:How To Category:Code Examples The following code snippet demonstrates how to use class [http://wiki.forum.nok...)
 
hamishwillee (Talk | contribs)
m (Hamishwillee - Bot update - Add ArticleMetaData)
 
(2 intermediate revisions by one user not shown)
Line 1: Line 1:
[[Category:Symbian C++]]
+
{{ArticleMetaData <!-- v1.2 -->
[[Category:Location Based Services]]
+
|sourcecode= <!-- Link to example source code e.g. [[Media:The Code Example ZIP.zip]] -->
[[Category:How To]]
+
|installfile= <!-- Link to installation file (e.g. [[Media:The Installation File.sis]]) -->
[[Category:Code Examples]]
+
|devices= <!-- Devices tested against - e.g. ''devices=Nokia 6131 NFC, Nokia C7-00'') -->
The following code snippet demonstrates how to use class [http://wiki.forum.nokia.com/index.php/Retrieving_location_information '''CPositionReader'''] for obtaining current device position. This snippet also demonstrates, how to find the nearest landmark according to the current position.
+
|sdk= <!-- SDK(s) built and tested against (e.g. [http://linktosdkdownload/ Qt SDK 1.1.4]) -->
 +
|platform= <!-- Compatible platforms - e.g. Symbian^1 and later, Qt 4.6 and later -->
 +
|devicecompatability= <!-- Compatible devices e.g.: All* (must have internal GPS) -->
 +
|dependencies= <!-- Any other/external dependencies e.g.: Google Maps Api v1.0 -->
 +
|signing= <!-- Signing requirements - empty or one of: Self-Signed, DevCert, Manufacturer -->
 +
|capabilities= <!-- Capabilities required by the article/code example (e.g. Location, NetworkServices. -->
 +
|keywords= <!-- APIs, classes and methods (e.g. QSystemScreenSaver, QList, CBase -->
 +
|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= 20080423
 +
|author= [[User:Den123]]
 +
}}
 +
[[Category:Location]][[Category:Symbian C++]]
 +
The following code snippet demonstrates how to use class [[Retrieving location information|'''CPositionReader''']] for obtaining current device position. This snippet also demonstrates, how to find the nearest landmark according to the current position.
  
 
Your class should implement interface '''CPositionReaderObserver''' and include instance of '''CPositionReader''' as a memeber.
 
Your class should implement interface '''CPositionReaderObserver''' and include instance of '''CPositionReader''' as a memeber.
Line 81: Line 100:
 
CleanupStack :: PopAndDestroy( 2 ); // iter db
 
CleanupStack :: PopAndDestroy( 2 ); // iter db
 
</code>
 
</code>
 +
 +
[[Category:How To]][[Category:Code Snippet]]

Latest revision as of 08:44, 25 July 2012

Article Metadata
Article
Created: Den123 (23 Apr 2008)
Last edited: hamishwillee (25 Jul 2012)

The following code snippet demonstrates how to use class CPositionReader for obtaining current device position. This snippet also demonstrates, how to find the nearest landmark according to the current position.

Your class should implement interface CPositionReaderObserver and include instance of CPositionReader as a memeber.

It is necessary to include the following additional headers:

  • epos_landmarks.h
  • epos_cposlmitemiterator.h
  • epos_cposlandmarkdatabase.h

Start async. request:

iReader = CPositionReader :: NewL( this );	
iReader->ReadPosInfo();

You should add the following code in the method ReadingComplete() for reading current location and finding the nearest landmark:

// read result device position
TPositionInfo& info = ( TPositionInfo& )aPosInfo;
TPosition position;
info.GetPosition( position );
 
// open default landmark DB
CPosLandmarkDatabase* db = CPosLandmarkDatabase :: OpenL();
CleanupStack :: PushL( db );
 
// create iterator
CPosLmItemIterator* iter = db->LandmarkIteratorL();
CleanupStack :: PushL( iter );
 
// distance between device position and current landmark
TReal32 distance = KMaxTReal32;
 
TPosLmItemId itemId = iter->NextL(), // current landmark ID
resultItemId = KPosLmNullItemId; // nearest landmark ID
while( itemId != KPosLmNullItemId )
{
// read current landmark
CPosLandmark* lm = db->ReadLandmarkLC( itemId );
 
// get current landmark position
TPosition lmPosition;
if( lm->GetPosition( lmPosition ) == KErrNone )
{
TReal32 d;
// check distance
if( position.Distance( lmPosition, d ) == KErrNone && d < distance )
{
resultItemId = itemId;
distance = d;
}
}
 
// read next landmark ID
itemId = iter->NextL();
CleanupStack :: PopAndDestroy(); // lm
}
 
// landmark was found
if( resultItemId != KPosLmNullItemId )
{
// read landmark from DB
CPosLandmark* resultLm = db->ReadLandmarkLC( resultItemId );
 
// read landmark name
TPtrC lmName;
resultLm->GetLandmarkName( lmName );
 
// show nearest landmark name
CAknInformationNote* informationNote;
informationNote = new ( ELeave ) CAknInformationNote;
informationNote->ExecuteLD( lmName );
 
CleanupStack :: PopAndDestroy(); // resultLm
}
 
CleanupStack :: PopAndDestroy( 2 ); // iter db
This page was last modified on 25 July 2012, at 08:44.
38 page views in the last 30 days.