Namespaces
Variants
Actions
Revision as of 09:21, 7 February 2012 by hamishwillee (Talk | contribs)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

How to obtain and save current location

Jump to: navigation, search
Article Metadata

Article
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 );
...
private:
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.

iReader->ReadPosInfo();

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:

79 page views in the last 30 days.
Nokia Developer aims to help you create apps and publish them so you can connect with users around the world.

京ICP备05048969号  © Copyright Nokia 2013 All rights reserved