How do I use the LBS API within a Qt Creator project?
What do I need to add to .pro?
Currently Qt Creator doesn't seem to locate any of the LBS headers (e.g. lbs.h, etc.)
How do I use the LBS API within a Qt Creator project?
What do I need to add to .pro?
Currently Qt Creator doesn't seem to locate any of the LBS headers (e.g. lbs.h, etc.)
Last edited by davkaplan; 2010-06-28 at 09:27.
With the Nokia Qt SDK, you purposefully have no access to native libraries (this would also defeat the purpose of Qt being cross platform). Instead, you should use the Qt Mobility APIs. Have a look at http://doc.qt.nokia.com/qtmobility-1...-overview.html for example code. See http://doc.qt.nokia.com/qtmobility-1...tmaps-pro.html for an example .pro file. The essential parts are the capabilities as well as the MOBILITY entry. If you don't want to target WinCE, you can safely ignore that part.
Ok, I get this - issue is that I don't think the mobility apis can do what I need - and I'd like to use Qt for interface + networking.
Specifically I'd like to return current location data (lat/lon) using whatever backend module (gps/network-based etc.).
However all I can see in the mobility location APIs is how to get location with the gps only?
You should implement own Qt class wrapping Symbian methods. I implemented it sometime ago. I can't post all src but below src. code should help you to understand the task. Please treat below src. as pseudo code.
iObserver - it your Qt class
void YourSymbianClass::ConstructL(const YourSymbianClass::TTechnologyType& aTechnologyType)
{
TPositionModuleId moduleId;
iTechnologyType=aTechnologyType;
if(iPosServer.Connect() != KErrNone)
{
// notify observer
User::Leave(KErrCouldNotConnect);
}
moduleId=ETechnologyTerminal ;
//:ETechnologyNetwork
// ETechnologyAssisted
// ETechnologyTerminal
if(iPositioner.Open(iPosServer,moduleId) != KErrNone)
{
//notify observer
iPosServer.Close();
User::Leave(KErrUnknown);
}
if(iPositioner.SetRequestor(CRequestor::ERequestorService,
CRequestor::EFormatApplication, KRequestor) != KErrNone)
{
// notify observer
iPositioner.Close();
iPosServer.Close();
User::Leave(KErrUnknown);
}
TPositionUpdateOptions updateOptions;
updateOptions.SetAcceptPartialUpdates(EFalse);
updateOptions.SetUpdateTimeOut(TTimeIntervalMicroSeconds(KTimeOut));
updateOptions.SetUpdateInterval(TTimeIntervalMicroSeconds(KTimerDelay));
if(iPositioner.SetUpdateOptions(updateOptions) != KErrNone)
{
// notify observer
iPositioner.Close();
iPosServer.Close();
User::Leave(KErrUnknown);
}
iState = EInitialized;
iTimer.CreateLocal();
iNestedSched = new (ELeave) CActiveSchedulerWait();
CActiveScheduler::Add(this); // Add to scheduler
}
TPosition YourSymbianClass::GetPosition()
{
TPosition pos;
iPositionInfo.GetPosition(pos);
//pos.Latitude(), pos.Longitude(), pos.Altitude())
return pos;;
}
void YourSymbianClass::RunL()
{
if(iState == EWaitForPositionUpdate)
{
TInt status = iStatus.Int();
switch(status)
{
case KErrNone:
{
if(iState == EWaitForPositionUpdate)
iObserver.PositionUpdated(GetPosition());
}
break;
}
}
Hi,
if you can still compile classic Symbian code, let me share my implementation also:
Header 1
Header 2Code:/* * ============================================================================== * Name : LbsPositionListener.h * Part of : LBSReference example application * Interface : * Description : Position listener interface * Version : 1.0 * * Copyright (c) 2005-2006 Nokia Corporation. * This material, including documentation and any related * computer programs, is protected by copyright controlled by * Nokia Corporation. * ============================================================================== */ #ifndef LBSPOSITIONLISTENER_H #define LBSPOSITIONLISTENER_H #include <lbsSatellite.h> class TPositionInfo; class TPositionSatelliteInfo; /** * Position data listener interface listens position information. * It can also be used to transfer error messages and codes. */ class MLbsPositionListener { public: /** * PositionInfoUpdatedL informs the listener about new location information * @param aModulename The name of the module which provided this information * @param aPosInfo Position information class */ virtual void PositionInfoUpdatedL(TPositionInfoBase& aPosInfo, const TDesC& aModulename) = 0; /** * ShowErrorL informs the listener about occurred error during position * request process * @param aErrorString The error in string format */ virtual void ShowErrorL(const TDesC& aErrorString) = 0; /** * ShowMessageL informs the listener about occurred event during position * request process * @param aMessage The message in string format */ virtual void ShowMessageL(const TDesC& aMessage) = 0; }; #endif //LBSPOSITIONLISTENER_H // End of File
Code:/* * ============================================================================== * Name : LbsPositionRequestor.h * Part of : LBSReference example application * Interface : * Description : Position requestor handles the position requesting process * Version : 1.0 * * Copyright (c) 2005-2006 Nokia Corporation. * This material, including documentation and any related * computer programs, is protected by copyright controlled by * Nokia Corporation. * ============================================================================== */ #ifndef LBSPOSITIONREQUESTOR_H #define LBSPOSITIONREQUESTOR_H // INCLUDES #include <lbs.h> #include <LbsSatellite.h> // FORWARD DECLARATIONS class MLbsPositionListener; // CLASS DECLARATION /** * Position requestor. * Request the position from the Location FW and * handles the position requesting process */ class CLbsPositionRequestor : public CActive { public: //Construction and destruction /** * Creates a new instance of a @ref CLbsPositionRequestor * @param aPositionListener Position listener to be registered * @return The newly created CLbsPositionRequestor object */ static CLbsPositionRequestor* NewL( MLbsPositionListener& aPositionListener ,TInt updateSecs) ; /** * Destructor. */ virtual ~CLbsPositionRequestor(); protected: // Functions from base classes // From CActive void DoCancel(); void RunL(); private: // New Functions /** * By default Symbian 2nd phase constructor is private. */ void ConstructL( ); /** * C++ default constructor. * @param aPositionListener Position listener to be registered */ CLbsPositionRequestor( MLbsPositionListener& aPositionListener , TInt updateSecs); /** * Starts a position requesting sequence */ void DoInitialiseL(); /** * Gets the name of the positioning module. If the name is not * available the name will be an empty string * @param aModuleId The id of the module */ void GetModuleName(const TPositionModuleId& aModuleId); /** * Preprocess the position information */ void PositionUpdatedL(); private: // Data //The id of the currently used PSY TPositionModuleId iUsedPsy; // Position server RPositionServer iPosServer; // Positioner RPositioner iPositioner; // Basic location info TPositionInfo iPositionInfo; // Satellite info TPositionSatelliteInfo iSatelliteInfo; // Position listener MLbsPositionListener& iPositionListener; // Module name TBuf<KPositionMaxModuleName> iModuleName; // The id of the used psy TPositionUpdateOptions iUpdateops; // Position info base TPositionInfoBase* iPosInfoBase; // State variable used to mark if we are // getting last known position TBool iGettingLastknownPosition; }; #endif //LBSPOSITIONREQUESTOR_H // End of File
The lines above are the best I have to offer.If anyone of you is of more advanced knowledge, I ask for your patience and understanding! - unknown arab poet
http://www.tamoggemon.com - Symbian blog - Windows Phone blog
My other blogs:
webOS blog iPhone blog BlackBerry blog Samsung bada blog Android blog
Code 1
Code:/* * ============================================================================== * Name : LbsPositionRequestor.cpp * Part of : LBSReference example application * Interface : * Description : Position requestor handles the position requesting process * Version : 1.0 * * Copyright (c) 2005-2006 Nokia Corporation. * This material, including documentation and any related * computer programs, is protected by copyright controlled by * Nokia Corporation. * ============================================================================== */ // INCLUDE FILES #include <Lbs.h> #include "gps/LBSPositionRequestor.h" #include "gps/LBSPositionlistener.h" // CONSTANTS //Second const TInt KSecond = 1000000; //Update time out const TInt KUpdateTimeOut = 15*KSecond; //MaxAge const TInt KMaxAge = 500000; // Unknown string used when module name is not known _LIT(KUnknown,"Unknown"); //The name of the requestor _LIT(KRequestor,"Location Reference Application"); // Event messages _LIT(KLastPosUnknown,"Last known position unknown."); //Error messages _LIT(KLbsErrLocRequest, "Request error: %d."); _LIT(KLbsErrAccess, "Access denied: %d."); _LIT(KLbsErrPosServConn, "Connecting to server: %d."); _LIT(KLbsErrOpenPos, "Opening a positioner: %d."); _LIT(KLbsErrSetRequestor, "Setting requestor: %d."); _LIT(KLbsErrSetUpOpt, "Setting update options: %d."); _LIT(KLbsErrCanceled, "Location request canceled."); _LIT(KLbsErrQualityLoss, "KPositionQualityLoss."); _LIT(KLbsErrTimedout, "Timed out."); // ============================ MEMBER FUNCTIONS =============================== // ----------------------------------------------------------------------------- // CLbsPositionRequestor::CLbsPositionRequestor // C++ default constructor can NOT contain any code, that // might leave. // ----------------------------------------------------------------------------- // CLbsPositionRequestor::CLbsPositionRequestor( MLbsPositionListener& aPositionListener, TInt updateSecs) : CActive(CActive::EPriorityStandard), iPositionListener( aPositionListener ), iPosInfoBase( &iPositionInfo ), iGettingLastknownPosition( ETrue ) { // Set update interval to one second to receive one position data per second iUpdateops.SetUpdateInterval(TTimeIntervalMicroSeconds(updateSecs*KSecond)); // If position server could not get position // In two minutes it will terminate the position request iUpdateops.SetUpdateTimeOut(TTimeIntervalMicroSeconds(KUpdateTimeOut)); // Positions which have time stamp below KMaxAge can be reused iUpdateops.SetMaxUpdateAge(TTimeIntervalMicroSeconds(KMaxAge)); // Enables location framework to send partial position data iUpdateops.SetAcceptPartialUpdates(ETrue); // Add this position requestor to the active scheduler CActiveScheduler::Add( this ); } // ----------------------------------------------------------------------------- // CLbsPositionRequestor::ConstructL // Symbian 2nd phase constructor can leave. // ----------------------------------------------------------------------------- // void CLbsPositionRequestor::ConstructL() { // Initialise the position request sequence DoInitialiseL(); } // ----------------------------------------------------------------------------- // CLbsPositionRequestor::NewL // Two-phased constructor. // ----------------------------------------------------------------------------- // CLbsPositionRequestor* CLbsPositionRequestor::NewL( MLbsPositionListener& aPositionListener ,TInt updateSecs) { //Create the object CLbsPositionRequestor* self = new( ELeave ) CLbsPositionRequestor( aPositionListener, updateSecs); //Push to the cleanup stack CleanupStack::PushL( self ); //Construct the object self->ConstructL(); //Remove from cleanup stack CleanupStack::Pop( self ); //Return pointer to the created object return self; } // ----------------------------------------------------------------------------- // CLbsPositionRequestor::~CLbsPositionRequestor // Destructor // ----------------------------------------------------------------------------- // CLbsPositionRequestor::~CLbsPositionRequestor() { // Cancel active object Cancel(); // Close the positioner iPositioner.Close(); // Close the session to the position server iPosServer.Close(); } // ----------------------------------------------------------------------------- // DoCancel() implements CActive DoCancel() // Implements the cancellation of an outstanding request. // ----------------------------------------------------------------------------- // void CLbsPositionRequestor::DoCancel() { // When a client application wishes to close one of its connections to Location // Server, there can be no outstanding requests on that particular connection // If a client application attempts to close a connection before outstanding // requests have been cancelled or completed, it is panicked //If we are getting the last known position if ( iGettingLastknownPosition ) { //Cancel the last known position request iPositioner.CancelRequest(EPositionerGetLastKnownPosition); } else { iPositioner.CancelRequest(EPositionerNotifyPositionUpdate); } } // ----------------------------------------------------------------------------- // RunL() implements CActive RunL() // Handles an active object’s request completion event. // ----------------------------------------------------------------------------- // void CLbsPositionRequestor::RunL() { TBuf<KPositionMaxModuleName> buffer; switch ( iStatus.Int() ) { // The fix is valid case KErrNone: // The fix has only partially valid information. // It is guaranteed to only have a valid timestamp case KPositionPartialUpdate: { // Pre process the position information PositionUpdatedL(); break; } // The data class used was not supported case KErrArgument: { // Set info base to position info iPosInfoBase = &iPositionInfo; // Request next position iPositioner.NotifyPositionUpdate( *iPosInfoBase, iStatus ); // Set this object active SetActive(); break; } // The position data could not be delivered case KPositionQualityLoss: { // Send event to position listener iPositionListener.ShowErrorL( KLbsErrQualityLoss );
The lines above are the best I have to offer.If anyone of you is of more advanced knowledge, I ask for your patience and understanding! - unknown arab poet
http://www.tamoggemon.com - Symbian blog - Windows Phone blog
My other blogs:
webOS blog iPhone blog BlackBerry blog Samsung bada blog Android blog
Code:if ( iGettingLastknownPosition ) { //Change the data class type iPosInfoBase = &iSatelliteInfo; } // Request position iPositioner.NotifyPositionUpdate( *iPosInfoBase, iStatus ); // Set this object active SetActive(); break; } // Access is denied case KErrAccessDenied: { // Send error to position listener buffer.Format(KLbsErrAccess, iStatus.Int()); iPositionListener.ShowErrorL(buffer); break; } // Request timed out case KErrTimedOut: { // Send error to position listener iPositionListener.ShowErrorL(KLbsErrTimedout); if ( iGettingLastknownPosition ) { //Change the data class type iPosInfoBase = &iSatelliteInfo; } // Request position iPositioner.NotifyPositionUpdate( *iPosInfoBase, iStatus ); // Set this object active SetActive(); break; } // The request was canceled case KErrCancel: { // Send error to position listener iPositionListener.ShowErrorL( KLbsErrCanceled ); break; } // There is no last known position case KErrUnknown: { // Send event to position listener iPositionListener.ShowMessageL(KLastPosUnknown); if ( iGettingLastknownPosition ) { //Change the data class type iPosInfoBase = &iSatelliteInfo; //Mark that we are not requesting NotifyPositionUpdate iGettingLastknownPosition = EFalse; } // Request next position iPositioner.NotifyPositionUpdate( *iPosInfoBase, iStatus ); // Set this object active SetActive(); break; } // Unrecoverable errors. default: { // Send error to position listener buffer.Format(KLbsErrLocRequest, iStatus.Int()); iPositionListener.ShowErrorL( buffer ); break; } } //We are not going to query the last known position anymore. if ( iGettingLastknownPosition ) { //Mark that we are not requesting NotifyPositionUpdate iGettingLastknownPosition = EFalse; } } // ----------------------------------------------------------------------------- // CLbsPositionRequestor::DoInitialiseL // Initialises position server and positioner and // begins the position request sequence. // ----------------------------------------------------------------------------- // void CLbsPositionRequestor::DoInitialiseL() { // Connect to the position server TInt error = iPosServer.Connect( ); TBuf<100> buffer; // The connection failed if ( KErrNone != error ) { // Show error to the user and leave buffer.Format(KLbsErrPosServConn, error); iPositionListener.ShowErrorL( buffer ); return; } // Open subsession to the position server error = iPositioner.Open(iPosServer); // The opening of a subsession failed if ( KErrNone != error ) { // Show error to the user and leave buffer.Format(KLbsErrOpenPos, error); iPositionListener.ShowErrorL( buffer ); iPosServer.Close(); return; } // Set position requestor error = iPositioner.SetRequestor( CRequestor::ERequestorService , CRequestor::EFormatApplication , KRequestor ); // The requestor could not be set if ( KErrNone != error ) { // Show error to the user and leave buffer.Format(KLbsErrSetRequestor, error); iPositionListener.ShowErrorL( buffer ); iPositioner.Close(); iPosServer.Close(); return; } // Set update options error = iPositioner.SetUpdateOptions( iUpdateops ); // The options could not be updated if ( KErrNone != error ) { // Show error to the user and leave buffer.Format(KLbsErrSetUpOpt, error); iPositionListener.ShowErrorL( buffer ); iPositioner.Close(); iPosServer.Close(); return; } // Get last known position. The processing of the result // is done in RunL method iPositioner.GetLastKnownPosition(*iPosInfoBase,iStatus); // Set this active object active SetActive(); } // ----------------------------------------------------------------------------- // CLbsPositionRequestor::GetModuleName // Gets the name of the positioning module by id. // ----------------------------------------------------------------------------- // void CLbsPositionRequestor::GetModuleName(const TPositionModuleId& aModuleId) { // Module information of the position module TPositionModuleInfo modInfo; // Get module info by module id TInt error = iPosServer.GetModuleInfoById( *&aModuleId, modInfo ); // If error occured if ( KErrNone != error ) { // Set the name of the module to 'Unknown' iModuleName = KUnknown; } else { // Get the name of the position module modInfo.GetModuleName(iModuleName); } } // ----------------------------------------------------------------------------- // CLbsPositionRequestor::PositionUpdatedL // Pre process the position information // ----------------------------------------------------------------------------- // void CLbsPositionRequestor::PositionUpdatedL() { //If we are getting the last known position if ( iGettingLastknownPosition ) { // Set the module name to 'Unknown' because last // known position has no module name iModuleName = KUnknown; // Send position information to registered listener iPositionListener.PositionInfoUpdatedL(*iPosInfoBase,iModuleName); //Change the data class type iPosInfoBase = &iSatelliteInfo; // Request next position iPositioner.NotifyPositionUpdate( *iPosInfoBase, iStatus ); // Set this object active SetActive(); } else { // Check if the id of the used PSY is 0 if ( 0 == iUsedPsy.iUid) { // Set the id of the currently used PSY iUsedPsy = iPosInfoBase->ModuleId(); } // Check if the position module has changed else if ( iPosInfoBase->ModuleId() != iUsedPsy ) { // Set the id of the currently used PSY iUsedPsy = iPosInfoBase->ModuleId(); //Position module info of new module TPositionModuleInfo moduleInfo; // Get module info iPosServer.GetModuleInfoById(iUsedPsy,moduleInfo); // Get classes supported TInt32 moduleInfoFamily = moduleInfo.ClassesSupported(EPositionInfoFamily); iPosInfoBase = &iSatelliteInfo; // Check if the new module supports // TPositionSatelliteInfo class if ( EPositionSatelliteInfoClass & moduleInfoFamily ) { // Set info base to satellite info iPosInfoBase = &iSatelliteInfo; } // The position module must support atleast // TPositionInfo class else { // Set info base to position info iPosInfoBase = &iPositionInfo; } } // Process the position information // and request next position // Get module name GetModuleName(iUsedPsy); // Send position information to registered listener iPositionListener.PositionInfoUpdatedL(*iPosInfoBase,iModuleName); // Request next position iPositioner.NotifyPositionUpdate( *iPosInfoBase, iStatus ); // Set this object active SetActive(); } } // End of File
Ah - and you will also need some libs...
The lines above are the best I have to offer.If anyone of you is of more advanced knowledge, I ask for your patience and understanding! - unknown arab poet
http://www.tamoggemon.com - Symbian blog - Windows Phone blog
My other blogs:
webOS blog iPhone blog BlackBerry blog Samsung bada blog Android blog