Please note that as of October 24, 2014, the Nokia Developer Wiki will no longer be accepting user contributions, including new entries, edits and comments, as we begin transitioning to our new home, in the Windows Phone Development Wiki. We plan to move over the majority of the existing entries over the next few weeks. Thanks for all your past and future contributions.

How to obtain and save current location

From Wiki
Jump to: navigation, search
Article Metadata
Created: Den123 (22 May 2008)
Last edited: hamishwillee (07 Feb 2012)

Class CPositionReader allows to obtain current location. The following code snippet demonstrates, how to obtain location and save it as landmark into default landmark database.

AppUi header:

class CYourAppUi : public CAknAppUi,
public MPositionReaderObserver
public: // from MPositionReaderObserver
void ReadingComplete( TPositionInfoBase& aPosInfo );
void ReadingError( TInt aErrorNo );
CPositionReader* iReader;

Initialization and deletion of iReader:

void CYourAppUi :: ConstructL()
iReader = CPositionReader :: NewL( this ); // new reader
CYourAppUi :: ~CYourAppUi()
delete iReader;
iReader = NULL;

You need to activate request for obtaining current location.


You can save current location after finishing of the request:

void CYourAppUi :: ReadingComplete( TPositionInfoBase& aPosInfo )
// reading current position info
TPositionInfo& info = ( TPositionInfo& )aPosInfo;
TPosition pos;
info.GetPosition( pos );
// open default landmark database
CPosLandmarkDatabase* db = NULL;
TRAPD( err, db = CPosLandmarkDatabase :: OpenL() );
if( err == KErrNone )
// create new landmark
CPosLandmark* lm = NULL;
TRAP( err, lm = CPosLandmark :: NewL() );
if( err == KErrNone )
// save position info
TRAP( err, lm->SetPositionL( pos ) );
if( err == KErrNone )
// fill landmark data
_LIT( KLmName, "Landmark Name" );
lm->SetLandmarkNameL( KLmName );
_LIT( KLmDescription, "Landmark Description" );
lm->SetLandmarkDescriptionL( KLmDescription );
_LIT( KLmCountry, "Landmark Country" );
lm->SetPositionFieldL( EPositionFieldCountry, KLmCountry );
_LIT( KLmCity, "Landmark City" );
lm->SetPositionFieldL( EPositionFieldCity, KLmCity);
_LIT( KLmStreet, "Landmark Street Name and Building Number" );
lm->SetPositionFieldL( EPositionFieldStreet, KLmStreet );
// save landmark
db->AddLandmarkL( *lm );
delete lm;
delete db;

Related Links:

This page was last modified on 7 February 2012, at 06:21.
24 page views in the last 30 days.

Was this page helpful?

Your feedback about this content is important. Let us know what you think.


Thank you!

We appreciate your feedback.