This page was last modified 06:06, 23 April 2008.
Obtaining current device position
From Forum Nokia Wiki
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
| Related Discussions | ||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| SettingPage()->ExecuteLD () TERMINATES | AS_r | Symbian User Interface | 4 | 2008-07-02 05:38 |
| CMdaAudioRecorderUtility only records 44 bytes | gammav | Symbian Media (Graphics & Sounds) | 9 | 2008-07-03 20:47 |
| 求助,Audio3例子中的错误 | Kiss_Fish | Symbian | 12 | 2006-03-13 01:38 |
| FullScreen Problem????????? | scorpio9 | Symbian User Interface | 6 | 2007-06-28 12:05 |
| Phone reboots upon uninstall | atonical | General Symbian C++ | 3 | 2008-04-09 07:18 |
