Archived:GPS API in Symbian 3rd Edition
The article is believed to be still valid for the original topic scope.
Article Metadata
Code Example
Article
+Before Anything+ There are many errors in this example, solution for each error is available at Archived Talk:GPS API in Symbian 3rd Edition
Overview
S60 3rd Edition has full support for GPS positioning. Both built-in and external Bluetooth GPS modules are supported. There are several GPS-enabled phones already on the market. They are Nokia 6110 and Nokia N95. More GPS phones are coming.
There is free GPS navigation software from Nokia called Smart2Go (another name is Nokia Maps). There are several 3rd party titles that also utilize GPS positioning. How can you use GPS positioning in your application?
Implementation
There are two ways. The first way is using low-level communication with external Bluetooth GPS module. It was widely used in S60 2nd Edition. It involves many technical issues and might not work correctly with some external Bluetooth GPS devices. It also will NOT work with the built-in GPS modules in Nokia 6110 and Nokia N95 phones. It’s a deprecated way.
The other (recommended) way is using Location API that was introduced in S60 2nd Edition, Feature Pack 2 and also supported in S60 3rd Edition.
There are several key classes in Location API. They are RPositionServer, RPositioner and TPositionInfo. First you need to connect to RPositionServer. Then create RPositioner object and issue an asynchronous request for current location. The result will be returned in TPositionInfo structure.
Usage
Here is a high-level utility class CGpsPositionRequest. It solves three problems. First, is hides all details and complexity of Location API from a user (programmer). Second, it works synchronously and removes all asynchronous complexity from the user. Third, a progress dialog (wait note) is being shown during the location request, so an end-user will see that an application is working. Here is a usage example:
#include "GpsPositionRequest.h"
...
// variables to hold current locations
TReal latitude, longitude;
// create CGpsPositionRequest object and put it into cleanup stack;
// pass application name as argument
CGpsPositionRequest* request = CGpsPositionRequest::NewLC(
_L("My application"));
// get current location (this operation can be long up to 30 seconds);
// progress dialog is shown to user during this time
TBool result = request->GetCurrentPostionL(latitude, longitude);
// delete request object
CleanupStack::PopAndDestroy(request);
// process result here
if (result)
{
// success, use latitude and longitude coordinates
}
else
{
// failed getting current position, show error message to user
}
Note that you also need to include the following lines into your MMP project file:
SOURCE GpsPositionRequest.cpp
LIBRARY lbs.lib
You will also need to include GpsPositionRequest.ra file into your resource file:
#include "GpsPositionRequest.ra"
Download the source code for CGpsPositionRequest from here:
File:GpsPositionRequest.zip
Another example that also has simple re-usable container that you could use for viewing the position before selecting it can be found from here: File:GeoTagging Example.zip


The example code won't compile because the NewLC method doesn't exist in the class.
---*1 Use NewL instead of NewLC
The zipped source code won't compile because the GetCurrentPositionL method isn't declared in the header file.
---*2 Replace GetCurrentPositionL by FetchCurrentLocationL
ECidWaitNote needs to be defined somewhere to get the code to compile.
---*3 Add this code to your *.hrh file
[code] enum TControlID { ECidWaitNote = 0x6666 }; [/code] note: you can also change the id and define it in your *.hrh file. you can also use another value.
Contents
Another error
The .ra file has EAknWaitNoteFlag instead of EAknWaitNoteFlags. Will not compile.
---*4 Copy the content of .ra file to your *.rssi file.
The correct function name for ---*2 is FetchCurrentPostionL // Govind Paul
One more!
After signing the file using a developer certificate and installing on the phone, when I open the application, I get a "System Error!". Any clue why this so?
---*5 The error: "System Error" is obtained because the file where you put the #include *.ra line is incorrect. Don't put this line in any file just do the item 4 with (---*4) mark.
Hope it helps - by joseph.m
Hello, I'm currently testing this example. I've got one question. It seems like it shows the coordinates with a very low precision? I mean it seems to retrive some coordinates but they stay the same when position changes (a change of about 50m) doesn't affect the coordinates. on the other hand the coordinates change in the standard Nokia GPS app (tools). any idea how to change the precision?
PallaviMajgaokar - One more
---6* Before
you need to push the "request". CleanupStack::PushL( request ); and then TBool result = request->GetCurrentPostionL(latitude, longitude);
But even after doing all these things, I did not get position at all! :(PallaviMajgaokar 19:54, 28 December 2011 (EET)
Hamishwillee - @PallaviMajgaokar - not correct
- How about instead of adding notes here you actually fix the code in the main article?
- PallaviMajgaokar - you're incorrect. The request is created using NewLC, so a copy of the object is left on the CleanupStack following construction. You would be correct if the object was created using NewL()
No idea why it doesn't work - assuming you're still using 3rd edition?hamishwillee 06:24, 3 January 2012 (EET)
PallaviMajgaokar - Hamishwillee
I am still using 3rd edition. My application crashes if I don't write that PopAndDestroy without the PushL. If some one else in the future would have the same error, they would atleast know what the probably solution might be.PallaviMajgaokar 12:17, 13 January 2012 (EET)