This tutorial explains how to get location information using the Location Acquisition API.
This section describes how to get location information using the Location Acquisition API.
Introduction
Client applications use the
GPS positioning modes
The Global Positioning System (GPS) is a technology that is often included in devices that support LBS.
For each location request from a client, the LBS subsystem can operate in one of several different GPS positioning modes. The Location Acquisition API hides the details of which GPS positioning mode is in use from client applications. A client makes the same sequence of calls to the API to get a position update whichever positioning mode is used. Note that only some of these positioning modes may be available to a client application at runtime.
Each GPS positioning mode is a different way of getting a position fix:
Autonomous
LBS uses a GPS Positioning Module to calculate position fixes without assistance data from the network. This mode typically takes the longest time to obtain a location fix compared to the other modes.
Terminal Based Mode
LBS uses an A-GPS Positioning Module to calculate position fixes using assistance data from the network. Assistance data specifies the GPS satellites that are above the horizon as seen from the mobile device's current location. Assistance data is used by an A-GPS Positioning Module to reduce the time necessary to obtain a position fix.
The network can also supply a reference position to the LBS subsystem as part of the sequence of events. This position is calculated in the network using cell-based techniques and may be less accurate than that obtained from GPS. If a reference position is available, it may be returned to the client before a GPS position.
See
Terminal Assisted Mode
LBS uses an A-GPS Positioning Module to obtain GPS measurements (using assistance data from the network). GPS measurements are the raw data used to calculate a GPS fix. Measurements are sent to the network and a position fix is calculated by a remote server. The remotely calculated position fix is returned to the mobile device and is known as the final network position. The LBS subsystem returns this position to the client.
Simultaneous Terminal Based Mode and Terminal Assisted Mode.
LBS passes GPS measurements to the network (as in Terminal Assisted Mode), but also attempts to use those measurements to calculate a GPS position fix (as in Terminal Based Mode). The position returned to the client may be either a GPS position (calculated in the mobile device) or a final network position (calculated using the measurements by a remote server in the network). The position that is calculated first (the GPS position or the final network position) is generally returned to the client. The final network position may also be returned to the client after the return of the GPS position.
Some devices also support a Cell-based Mode in which LBS obtains a position fix from the network without using GPS. This position fix is sometimes less accurate than that obtained using GPS.
A client application cannot directly choose the GPS positioning mode that is used for its location request. A handset manufacturer may provide an LBS settings application where the GPS mode can be selected by an end user. However for modes that involve the network (Terminal Based Mode, Terminal Assisted Mode and Cell-based Mode) it is possible for a network operator to override the GPS mode as part of the location request. If a client wants to know precisely how a position fix was calculated, this information is available in the returned position info object (as described in more detail later in this document).
Example sequence
Figure 1 shows a simplified sequence for a client requesting a position update from LBS. The sequence shows simplified behaviour for Terminal Based Mode. The A-GPS Module is a Positioning Module that uses Assisted GPS to calculate a position. The Network Protocol Module is a Positioning Module that obtains GPS assistance data and reference positions (often approximate positions) from the network. Note that Terminal Based Mode may not be available on all mobile devices. This depends on the Positioning Modules that have been installed by the mobile device creator.
Example code and description
The following code shows a simple example of how a client application can get a single position update. The numbers in the code comments refer to sections that follow the code example.
The following describes the steps to get location information as shown in the above example:
1. Create a session with the Location Server
To create a session with the Location Server, a client application:
Creates an instance of
Calls
Standard client-server error codes are returned by calls to open the session. A panic occurs if the client application has already created a session with the Location Server. Error and panic codes specific to LBS are defined in
2. Create a subsession with the Location Server
Location information requests are issued on a subsession.
To create a subsession, an application calls one of three overloaded
See
The LBS subsystem does not compare the vertical accuracy of a calculated position with the vertical accuracy specified by a client application (specified by position quality criteria, by a quality profile or by a Positioning Module). Only the horizontal accuracy of a calculated position is used to decide if it is accurate enough to be returned to a client application.
3. Set client requester details
A client application can specify the client requesters by calling
This is an optional step. Calling
See
4. Set update options
A client application calls
A
The time interval between position updates
Setting a non-zero value indicates that the client requires periodic updates (this is also known as 'tracking'). LBS attempts to send position updates to the client application with this interval between the updates. Note that setting
Note that when a client application is tracking, LBS does not return reference positions as periodic updates. See the section on Tracking later in this document for more information on tracking behaviour.
A position update timeout
After a timeout the value set for the client's
Note that calling SetUpdateTimeOut() with a value of 0 (or not setting it) indicates that LBS should not timeout the location request from a client.
The maximum age of a position update
Acceptance of partial updates
A partial update is a position update that contains only partial position data. Such a position is called an incomplete position. An example of an incomplete position is one that contains data about the satellites used to obtain a GPS fix but no latitude or longitude data.
If partial updates are not set the default behaviour is for
Important note on setting update options
The default constructor of
When setting update options, a client should beware of causing unexpected side effects. For example, if a client wants to accept partial updates, it might do the following:
Create a new
Call
Call
However, this process has the side-effect of setting all the other update options to their default values as described above. In particular the client request will now not timeout which is unlikely to be the desired behaviour. To avoid this, a client should usually modify the current update options as follows:
Get the current update options by calling
Call the appropriate
Call
Examples
The following code shows a simple example of how to set update options. Note that all the options are changed by the client.
The following code example shows an example of how to change one update option (to accept partial updates).
Notes
When a call to
A client application can only have one outstanding request for location information per
5. Request the location information
An application can call one the following methods to obtain position data:
RPositioner::NotifyPositionUpdate()
A client application calls
See
RPositioner::GetLastKnownPosition()
A client application calls
If the LBS subsystem has a position from a previous request a call to
RPositioner::GetLastKnownPositionArea()
A client application calls
A client passes in
On completion,
If successful,
See
See
The following code fragment shows how to use the method and check the accuracy of the returned position:
Client applications must always check the value of the
The value of
6. Receive and use the location information
When the Location Server obtains a position, the client's
Important notes
An application should test what kind of position is returned by
A reference position may be returned to a client application by the Location Server before a more accurate position fix is available. Whether a reference position is made available to the Location Server depends on the implementation of the Positioning Modules by the Symbian device creator or handset manufacturer.
If a reference position is returned, the behaviour is as follows:
For the first call to RPositioner::NotifyPositionUpdate()
For subsequent calls to RPositioner::NotifyPositionUpdate() (made by the same client subsession)
Calculated in the mobile device by GPS with assistance data (for Terminal Based Mode)
Returned from the network, a position known as the final network position (for Terminal Assisted Mode)
The value of
Normal behaviour is to return
Note that
Tracking
A position update time line for tracking is shown in figure 2. Note that the exact behaviour of tracking on systems may differ from that shown in Figure 2.
A client application has previously called
A client application makes its first call to
After a time t, the client's
At a time t + T (where T is the update interval) the client's
The next position update is expected at time t + 2T, but in the case shown in figure 2 this is not possible (the mobile device may have moved into an area where the GPS signal is weak). In general if it is not possible to obtain an accurate GPS fix by time t + nT, but the fix is obtained a short time later, the next position update is delivered as soon as possible after time t + nT (after t + 2T in figure 2).
The client makes its next call to
The important point to note is that LBS attempts to deliver position updates at regular times t + nT but the time interval between position updates may temporarily be greater than or less than T.
Note that if partial updates were enabled, an incomplete position would be delivered at time t + 2T if it were available. Also note that an inaccurate position would be delivered if one was available at that time and LBS was configured to return it.
Error codes
The value of a client's
7. Cancel or complete a location information request
To cancel a location request a client application calls
To complete a location request early, a client application calls
8. Close the subsession and session
This tutorial explains how to get location information using the Location Acquisition API.
This section describes how to get location information using the Location Acquisition API.
Introduction
Client applications use the
GPS positioning modes
The Global Positioning System (GPS) is a technology that is often included in devices that support LBS.
For each location request from a client, the LBS subsystem can operate in one of several different GPS positioning modes. The Location Acquisition API hides the details of which GPS positioning mode is in use from client applications. A client makes the same sequence of calls to the API to get a position update whichever positioning mode is used. Note that only some of these positioning modes may be available to a client application at runtime.
Each GPS positioning mode is a different way of getting a position fix:
Autonomous
LBS uses a GPS Positioning Module to calculate position fixes without assistance data from the network. This mode typically takes the longest time to obtain a location fix compared to the other modes.
Terminal Based Mode
LBS uses an A-GPS Positioning Module to calculate position fixes using assistance data from the network. Assistance data specifies the GPS satellites that are above the horizon as seen from the mobile device's current location. Assistance data is used by an A-GPS Positioning Module to reduce the time necessary to obtain a position fix.
The network can also supply a reference position to the LBS subsystem as part of the sequence of events. This position is calculated in the network using cell-based techniques and may be less accurate than that obtained from GPS. If a reference position is available, it may be returned to the client before a GPS position.
See
Terminal Assisted Mode
LBS uses an A-GPS Positioning Module to obtain GPS measurements (using assistance data from the network). GPS measurements are the raw data used to calculate a GPS fix. Measurements are sent to the network and a position fix is calculated by a remote server. The remotely calculated position fix is returned to the mobile device and is known as the final network position. The LBS subsystem returns this position to the client.
Simultaneous Terminal Based Mode and Terminal Assisted Mode.
LBS passes GPS measurements to the network (as in Terminal Assisted Mode), but also attempts to use those measurements to calculate a GPS position fix (as in Terminal Based Mode). The position returned to the client may be either a GPS position (calculated in the mobile device) or a final network position (calculated using the measurements by a remote server in the network). The position that is calculated first (the GPS position or the final network position) is generally returned to the client. The final network position may also be returned to the client after the return of the GPS position.
Some devices also support a Cell-based Mode in which LBS obtains a position fix from the network without using GPS. This position fix is sometimes less accurate than that obtained using GPS.
A client application cannot directly choose the GPS positioning mode that is used for its location request. A handset manufacturer may provide an LBS settings application where the GPS mode can be selected by an end user. However for modes that involve the network (Terminal Based Mode, Terminal Assisted Mode and Cell-based Mode) it is possible for a network operator to override the GPS mode as part of the location request. If a client wants to know precisely how a position fix was calculated, this information is available in the returned position info object (as described in more detail later in this document).
Example sequence
Figure 1 shows a simplified sequence for a client requesting a position update from LBS. The sequence shows simplified behaviour for Terminal Based Mode. The A-GPS Module is a Positioning Module that uses Assisted GPS to calculate a position. The Network Protocol Module is a Positioning Module that obtains GPS assistance data and reference positions (often approximate positions) from the network. Note that Terminal Based Mode may not be available on all mobile devices. This depends on the Positioning Modules that have been installed by the mobile device creator.
Example code and description
The following code shows a simple example of how a client application can get a single position update. The numbers in the code comments refer to sections that follow the code example.
The following describes the steps to get location information as shown in the above example:
1. Create a session with the Location Server
To create a session with the Location Server, a client application:
Creates an instance of
Calls
Standard client-server error codes are returned by calls to open the session. A panic occurs if the client application has already created a session with the Location Server. Error and panic codes specific to LBS are defined in
2. Create a subsession with the Location Server
Location information requests are issued on a subsession.
To create a subsession, an application calls one of three overloaded
See
The LBS subsystem does not compare the vertical accuracy of a calculated position with the vertical accuracy specified by a client application (specified by position quality criteria, by a quality profile or by a Positioning Module). Only the horizontal accuracy of a calculated position is used to decide if it is accurate enough to be returned to a client application.
3. Set client requester details
A client application can specify the client requesters by calling
This is an optional step. Calling
See
4. Set update options
A client application calls
A
The time interval between position updates
Setting a non-zero value indicates that the client requires periodic updates (this is also known as 'tracking'). LBS attempts to send position updates to the client application with this interval between the updates. Note that setting
Note that when a client application is tracking, LBS does not return reference positions as periodic updates. See the section on Tracking later in this document for more information on tracking behaviour.
A position update timeout
After a timeout the value set for the client's
Note that calling SetUpdateTimeOut() with a value of 0 (or not setting it) indicates that LBS should not timeout the location request from a client.
The maximum age of a position update
Acceptance of partial updates
A partial update is a position update that contains only partial position data. Such a position is called an incomplete position. An example of an incomplete position is one that contains data about the satellites used to obtain a GPS fix but no latitude or longitude data.
If partial updates are not set the default behaviour is for
Important note on setting update options
The default constructor of
When setting update options, a client should beware of causing unexpected side effects. For example, if a client wants to accept partial updates, it might do the following:
Create a new
Call
Call
However, this process has the side-effect of setting all the other update options to their default values as described above. In particular the client request will now not timeout which is unlikely to be the desired behaviour. To avoid this, a client should usually modify the current update options as follows:
Get the current update options by calling
Call the appropriate
Call
Examples
The following code shows a simple example of how to set update options. Note that all the options are changed by the client.
The following code example shows an example of how to change one update option (to accept partial updates).
Notes
When a call to
A client application can only have one outstanding request for location information per
5. Request the location information
An application can call one the following methods to obtain position data:
RPositioner::NotifyPositionUpdate()
A client application calls
See
RPositioner::GetLastKnownPosition()
A client application calls
If the LBS subsystem has a position from a previous request a call to
RPositioner::GetLastKnownPositionArea()
A client application calls
A client passes in
On completion,
If successful,
See
See
The following code fragment shows how to use the method and check the accuracy of the returned position:
Client applications must always check the value of the
The value of
6. Receive and use the location information
When the Location Server obtains a position, the client's
Important notes
An application should test what kind of position is returned by
A reference position may be returned to a client application by the Location Server before a more accurate position fix is available. Whether a reference position is made available to the Location Server depends on the implementation of the Positioning Modules by the Symbian device creator or handset manufacturer.
If a reference position is returned, the behaviour is as follows:
For the first call to RPositioner::NotifyPositionUpdate()
For subsequent calls to RPositioner::NotifyPositionUpdate() (made by the same client subsession)
Calculated in the mobile device by GPS with assistance data (for Terminal Based Mode)
Returned from the network, a position known as the final network position (for Terminal Assisted Mode)
The value of
Normal behaviour is to return
Note that
Tracking
A position update time line for tracking is shown in figure 2. Note that the exact behaviour of tracking on systems may differ from that shown in Figure 2.
A client application has previously called
A client application makes its first call to
After a time t, the client's
At a time t + T (where T is the update interval) the client's
The next position update is expected at time t + 2T, but in the case shown in figure 2 this is not possible (the mobile device may have moved into an area where the GPS signal is weak). In general if it is not possible to obtain an accurate GPS fix by time t + nT, but the fix is obtained a short time later, the next position update is delivered as soon as possible after time t + nT (after t + 2T in figure 2).
The client makes its next call to
The important point to note is that LBS attempts to deliver position updates at regular times t + nT but the time interval between position updates may temporarily be greater than or less than T.
Note that if partial updates were enabled, an incomplete position would be delivered at time t + 2T if it were available. Also note that an inaccurate position would be delivered if one was available at that time and LBS was configured to return it.
Error codes
The value of a client's
7. Cancel or complete a location information request
To cancel a location request a client application calls
To complete a location request early, a client application calls
8. Close the subsession and session