×
Namespaces

Variants
Actions
(Difference between revisions)

How to export landmarks from database to file

From Nokia Developer Wiki
Jump to: navigation, search
hamishwillee (Talk | contribs)
m (Hamishwillee - Adding missing translation link)
hamishwillee (Talk | contribs)
m (Hamishwillee - Bot update - Add ArticleMetaData)
 
Line 1: Line 1:
 +
{{ArticleMetaData <!-- v1.2 -->
 +
|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]]) -->
 +
|devices= <!-- Devices tested against - e.g. ''devices=Nokia 6131 NFC, Nokia C7-00'') -->
 +
|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= 20080411
 +
|author= [[User:Den123]]
 +
}}
 
[[Category:Location]][[Category:Symbian C++]]
 
[[Category:Location]][[Category:Symbian C++]]
 
Class '''CPosLandmarkEncoder''' allows to encode landmark content. You can use this class for exporting landmarks from database to local files. The type (e.g. the mime type) must be specified for creating instance of this class. You can use following mime type for exporting landmarks to the XML-file: '''"application/vnd.nokia.landmarkcollection+xml"'''.
 
Class '''CPosLandmarkEncoder''' allows to encode landmark content. You can use this class for exporting landmarks from database to local files. The type (e.g. the mime type) must be specified for creating instance of this class. You can use following mime type for exporting landmarks to the XML-file: '''"application/vnd.nokia.landmarkcollection+xml"'''.
Line 112: Line 134:
 
* [[How to manage landmark categories]]
 
* [[How to manage landmark categories]]
  
[[Category:How To]][[Category:Code Examples]]
+
[[Category:How To]][[Category:Code Snippet]]
 
<!-- Translation --> [[ru:Экспорт ориентиров]]
 
<!-- Translation --> [[ru:Экспорт ориентиров]]

Latest revision as of 06:08, 26 July 2012

Article Metadata
Article
Created: Den123 (11 Apr 2008)
Last edited: hamishwillee (26 Jul 2012)

Class CPosLandmarkEncoder allows to encode landmark content. You can use this class for exporting landmarks from database to local files. The type (e.g. the mime type) must be specified for creating instance of this class. You can use following mime type for exporting landmarks to the XML-file: "application/vnd.nokia.landmarkcollection+xml".

Next code snippet demonstrates how to export all local landmark databases to the XML-files.

It is necessary to include the following headers:

#include <epos_cposlmdatabasemanager.h>
#include <epos_cposlandmarkencoder.h>
#include <bautils.h> // - for BAFLUTILS

And link against:

LIBRARY eposlmdbmanlib.lib
LIBRARY eposlandmarks.lib
LIBRARY bafl.lib // - for BaflUtils

Source:

// we need RFs for some checks
RFs rFs;
User::LeaveIfError( rFs.Connect() );
CleanupClosePushL( rFs );
 
// backup folder
_LIT( KBackupFolder, "C:\\LmBackup\\" );
 
// check backup folder
TFileName backupFolder( KBackupFolder );
BaflUtils :: EnsurePathExistsL( rFs, backupFolder );
 
// for file name
_LIT( KReplace, "_" );
TBuf<1> replaceStr( KReplace );
 
// db manager
CPosLmDatabaseManager* dbManager = CPosLmDatabaseManager :: NewL();
CleanupStack :: PushL( dbManager );
 
// protocol for the local DBs
_LIT( KFileProto, "file" );
 
// array, that contains URI of the local DBs
CDesCArray* dbUriList = dbManager->ListDatabasesLC( KFileProto );
 
// MIME type for import & export
_LIT8( KPosMimeTypeLandmarkCollectionXml, "application/vnd.nokia.landmarkcollection+xml" );
 
// Create the encoder to be used for exporting landmarks
CPosLandmarkEncoder* encoder = CPosLandmarkEncoder::NewL(KPosMimeTypeLandmarkCollectionXml);
CleanupStack :: PushL( encoder );
 
// array of the export items
RArray<TPosLmItemId> itemsArray;
CleanupClosePushL( itemsArray );
 
for( TInt i = 0; i < dbUriList->Count(); i++ )
{
// open current database
TPtrC currentUri = (*dbUriList)[i];
CPosLandmarkDatabase* db = CPosLandmarkDatabase :: OpenL( currentUri );
CleanupStack :: PushL( db );
 
// iterator allows to read the database landmarks
CPosLmItemIterator* iter = db->LandmarkIteratorL();
CleanupStack::PushL( iter );
 
// if iterator is not empty
if( iter->NumOfItemsL() > 0 )
{
// fetch IDs of all landmarks
itemsArray.Reset();
iter->GetItemIdsL( itemsArray, 0, iter->NumOfItemsL() );
 
// filename from URI: file://e:my.ldb -> C:\LmBackup\e_my.ldb
TFileName fileName( backupFolder );
fileName.Append( currentUri.Right( currentUri.Length() - 7 ) );
fileName.Replace( backupFolder.Length() + 1, 1, replaceStr ); // : -> _
 
// if file already exists - delete file
if( BaflUtils :: FileExists( rFs, fileName ) )
BaflUtils :: DeleteFile( rFs, fileName );
 
// point out the file to export landmark data to
encoder->SetOutputFileL( fileName );
 
// execute export in batch mode
ExecuteAndDeleteLD( db->ExportLandmarksL( *encoder, itemsArray,
CPosLandmarkDatabase::EIncludeCategories ) );
 
// finalize encoding to complete export ( in batch mode )
ExecuteAndDeleteLD( encoder->FinalizeEncodingL() );
}
CleanupStack :: PopAndDestroy( 2 ); // iter db
}
CleanupStack :: PopAndDestroy( 5 ); // rFs itemsArray encoder iDbList dbManager

[edit] Internal Links

This page was last modified on 26 July 2012, at 06:08.
56 page views in the last 30 days.
×