×
Namespaces

Variants
Actions

Searching for GPS devices using Symbian C++

From Nokia Developer Wiki
Jump to: navigation, search

Archived.pngArchived: This article is archived because it is not considered relevant for third-party developers creating commercial solutions today. If you think this article is still relevant, let us know by adding the template {{ReviewForRemovalFromArchive|user=~~~~|write your reason here}}.

The article is believed to be still valid for the original topic scope.


Article Metadata
Tested with
Devices(s): Nokia E90 Communicator, Nokia N95
Compatibility
Platform(s): S60 3rd Edition
S60 3rd Edition, FP1

S60 3rd Edition FP1
S60 3rd Edition (initial release)
Article
Keywords: RPositionServer, TPositionModuleId, TPositionModuleStatus
Created: tepaa (08 Feb 2008)
Last edited: jasfox (25 Apr 2013)

Contents

Overview

The following example goes through the GPS devices of the mobile phone and selects the device used for GPS positioning.

If the code finds both an external Bluetooth GPS device and an internal GPS device, it selects the internal one.


MMP file

The following capabilities and libraries are required:

CAPABILITY Location

LIBRARY Lbs.lib


Header file

#include <lbs.h>

Source file

// Finds and selects GPS device
TPositionModuleId CYourClass::GetPositionModuleId()
{
TInt error = KErrNone;
 
RPositionServer ps; // TODO: Move to the class member variable
error = ps.Connect();
if (error != KErrNone)
{
return KNullUid;
}
 
TUint numModules = 0;
error = ps.GetNumModules(numModules);
if (error != KErrNone)
{
ps.Close(); // TODO: No need to close RPositionServer if it is moved
// to class member variable, then it must close in class
// destructor.
return KNullUid;
}
 
TPositionModuleId currentModuleId = KNullUid;
TPositionModuleId selectedModuleId = KNullUid;
for (TInt moduleIndex = 0; moduleIndex < numModules; moduleIndex++)
{
TPositionModuleInfo moduleInfo;
error = ps.GetModuleInfoByIndex(moduleIndex, moduleInfo);
if (error != KErrNone)
{
ps.Close(); // TODO: No need to close RPositionServer if it is
// moved to class member variable, then it must close
// in class destructor.
return selectedModuleId;
}
 
currentModuleId = moduleInfo.ModuleId();
 
TPositionModuleStatus moduleStatus;
error = ps.GetModuleStatus(moduleStatus, currentModuleId);
if (error != KErrNone ||
moduleStatus.DeviceStatus() == TPositionModuleStatus::EDeviceDisabled)
{
continue;
}
 
TPositionModuleInfo::TDeviceLocation deviceLoc =
moduleInfo.DeviceLocation();
if (deviceLoc == TPositionModuleInfo::EDeviceInternal)
{
if (selectedModuleId == KNullUid)
{
// Found first internal position module, select that
selectedModuleId = currentModuleId;
}
else
{
// Check external module should be switched to internal
TPositionModuleInfo selectedModuleInfo;
error = ps.GetModuleInfoById(selectedModuleId,
selectedModuleInfo);
if (error == KErrNone && selectedModuleInfo.DeviceLocation()
== TPositionModuleInfo::EDeviceExternal)
{
// Change external device to internal
selectedModuleId = currentModuleId;
}
}
}
else if (deviceLoc == TPositionModuleInfo::EDeviceExternal)
{
// Just pick the first external device, if none is currently
// selected
if (selectedModuleId == KNullUid)
{
// Found first enternal position module, select that
selectedModuleId = currentModuleId;
}
}
}
 
ps.Close(); // TODO: No need to close RPositionServer if it is moved to
// class member variable, then it must close in class
// destructor.
return selectedModuleId;
}
 
 
// Use selected GPS device
void CYourClass::OpenPositioner(TPositionModuleId aDevice)
{
RPositioner positioner; // TODO: Move to the class member variable
RPositionServer ps; // TODO: Move to the class member variable
 
if (aDevice != KNullUid)
{
if (ps.Connect() == KErrNone)
{
// Selected GPS device goes as 'aDevice' parameter
positioner.Open(ps,aDevice);
...
positioner.Close();
ps.Close();
}
}
}
This page was last modified on 25 April 2013, at 11:07.
48 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.

×