Join Now
Quality Rating:
  • Currently 0.0 / 5
(0.0 / 5 - 0 votes cast)
Expertise Level:
  • Currently 0.0 / 5
(0.0 / 5 - 0 votes cast)

This page was last modified 21:20, 6 March 2008.

CS000822 - Searching for GPS devices

From Forum Nokia Wiki


ID CS000822 Creation date February 15, 2008
Platform S60 3rd Edition
S60 3rd Edition, FP1
Tested on devices Nokia E90 Communicator, Nokia N95
Category Symbian C++ Subcategory Location Based Services
APIs   Classes RPositionServer
TPositionModuleId
TPositionModuleStatus
Methods      

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();
            }
        }
    }
Related Discussions
Thread Thread Starter Forum Replies Last Post
MWS location does not work ueffchen Mobile Web Server 6 2008-08-28 09:45
Location APIs using bluetooth lucca99 Bluetooth Technology 1 2007-06-17 02:58
Service discovery and connection? gnhansen Bluetooth Technology 3 2004-12-06 20:52
GPS on N95 and java edudesouza Mobile Java Tools & SDKs 16 2007-07-18 09:13
Find longitude and latitude kkrish Symbian Tools & SDKs 12 2008-08-21 22:21
 
Powered by MediaWiki
     
     RDF Facets:
     
     
     qfnZtypeQUqfnTypeZCommunityContentQ
     qfnZtypeQUqfnTypeZWebpageQ
     qfnZtypeQUqfnTypeZWikiContentQ
     qmarsZlanguageQUxhttpE3aE2fE2fswE2enokiaE2ecomE2flanguageE2d1E2fenX