QGeoPositionInfoSource
#include <QtLocationSubset/QGeoPositionInfoSource>
The QGeoPositionInfoSource class is an abstract base class for the distribution of positional updates.
1.0
The static function QGeoPositionInfoSource::createDefaultSource() creates a default position source on the BlackBerry platform.
Users of a QGeoPositionInfoSource subclass can request the current position using requestUpdate(), or start and stop regular position updates using startUpdates() and stopUpdates(). When an update is available, positionUpdated() is emitted. The last known position can be accessed with lastKnownPosition().
If regular position updates are required, setUpdateInterval() can be used to specify how often these updates should be emitted. If no interval is specified, updates are simply provided whenever they are available. For example:
// Emit updates every 10 seconds if available
QGeoPositionInfoSource *source = QGeoPositionInfoSource::createDefaultSource(0);
if (source)
source->setUpdateInterval(10000);
To remove an update interval that was previously set, call setUpdateInterval() with a value of 0.
Note that the position source may have a minimum value requirement for update intervals, as returned by minimumUpdateInterval().
Users of a BlackBerry QGeoPositionInfoSource subclass (obtained from QGeoPositionInfoSource::createDefaultSource()) can access the underlying backend (BlackBerry Location Manager) for additional functionality via the Qt property system.
The following properties extend QGeoPositionInfoSource allowing use of additional features of the BlackBerry Location Manager. They correspond to the fields of the dat parameter of the location request. Set these properties prior to calling startUpdates() or requestUpdate().
source->setProperty( "period", 5.0 );
source->setProperty( "accuracy", 2.0 );
source->setProperty( "responseTime", 10.0 );
source->setProperty( "canRunInBackground", true );
source->setProperty( "provider", "hybrid" ); // equivalent to QGeoPositionInfoSource::AllPositioningMethods source->setProperty( "provider", "gnss" ); // equivalent to QGeoPositionInfoSource::SatellitePositioningMethods source->setProperty( "provider", "network" ); // equivalent to QGeoPositionInfoSource::NonSatellitePositioningMethods
source->setProperty( "provider", "network" ); source->setProperty( "fixType", "wifi" );
source->setProperty( "appId", "myId" ); source->setProperty( "appPassword", "myPassword" );
This property specifies a special application password, goes with appId above.
QUrl url("tcp://user:pass@address.dom:1234");
source->setProperty( "pdeUrl", url );
QUrl url("tcp://user:pass@address.dom:1234");
source->setProperty( "slpUrl", url );
// To link against these classes, add the following line to your .pro file : LIBS += -lbbsystem
#include <bb/system/InvokeManager>
#include <bb/system/InvokeRequest>
#include <bb/system/InvokeTargetReply>
.
.
.
// ensure location services are enabled
if ( !positionInfoSource->property("locationServicesEnabled").toBool() ) {
// bring up the Settings app at the Location Services page so it can be turned on. One could
// first bring up a dialog here to give the user context
bb::system::InvokeManager * invokeManager = new bb::system::InvokeManager( NULL ); // or pass a QObject parent instead of NULL to relinquish delete responsibility
bb::system::InvokeRequest request;
request.setAction( "bb.action.OPEN" );
request.setMimeType( "text/html" );
request.setUri( "settings://location" );
request.setTarget( "sys.settings.target" );
bb::system::InvokeTargetReply *reply = invokeManager->invoke(request);
if ( reply ) {
// you can use reply to see how the invocation went...
}
delete invokeManager; // deletes reply too...
}
double hdop = 20.0; // horizontal dilution of precision
QVariant variant = source->property("replyDat");
if ( variant.isValid() ) {
// the replyDat property is a QVariantMap
QVariantMap rawDat = variant.toMap();
QVariant field = rawDat.value( "hdop" );
if ( field.isValid() ) {
hdop = field.toDouble();
}
}
Accessing satellite data can be done like this: // This example gets the carrier-to-noise ratio for the first satellite in the list.
double cno = 0.0; // satellite carrier-to-noise ratio
QVariant variant = source->property("replyDat");
if ( variant.isValid() ) {
// the replyDat property is a QVariantMap
QVariantMap rawDat = variant.toMap();
QVariant field = rawDat.value( "satellites" );
if ( field.isValid() ) {
// the satellites data is stored in a QVariantList
QVariantList satArray = field.toList();
// each element in the list is a QVariantMap corresponding to info for a single satellite.
// Here we just access the first satellite in the list
QVariantMap satInfo = satArray.at(0).toMap();
QVariant satField = satInfo.value( "cno" );
cno = satField.toDouble();
}
}
#include <bb/location/PositionErrorCode>
.
.
.
// A timeout has occurred, check if the LM has reported an error
if ( positionInfoSource->property("replyErrorCode").isValid() ) {
bb::location::PositionErrorCode::Type errorCode = positionInfoSource->property("replyErrorCode").value<bb::location::PositionErrorCode::Type>();
std::cout << "LM Error Code: ";
switch ( errorCode ) {
// this error code should not be encountered here (included for completeness)
case bb::location::PositionErrorCode::None:
std::cout << "None" << std::endl;
break;
case bb::location::PositionErrorCode::FatalDisabled:
std::cout << "Fatal - disabled (turn on location services!)" << std::endl;
break;
// this error code should not normally be encountered, may require setting
// the reset property to resolve.
case bb::location::PositionErrorCode::FatalInsufficientProviders:
std::cout << "Fatal - insufficient providers" << std::endl;
break;
// this error code could be encountered if an invalid value is set for a
// property related to a BlackBerry Location Manager feature.
case bb::location::PositionErrorCode::FatalInvalidRequest:
std::cout << "Fatal - invalid request" << std::endl;
break;
// the following warning codes are simply to provide more information;
// if periodic updates are active they will resume when conditions change.
// It may be opportune to inform the user that finding the location is
// taking longer than expected.
case bb::location::PositionErrorCode::WarnTimeout:
std::cout << "Warning - timeout" << std::endl;
break;
case bb::location::PositionErrorCode::WarnLostTracking:
std::cout << "Warning - lost tracking" << std::endl;
break;
default:
std::cout << "Unknown (bad enum value)" << std::endl;
break;
}
}
positionInfoSource->setProperty("reset", "hot");
positionInfoSource->requestUpdate();
Public Types Index
enum PositioningMethodSatellitePositioningMethods = 0x000000ff, NonSatellitePositioningMethods = 0xffffff00, AllPositioningMethods = 0xffffffff |
Properties Index
| int | updateInterval |
| int | minimumUpdateInterval [read-only] |
Public Functions Index
| QGeoPositionInfoSource (QObject *parent) | |
| virtual | ~QGeoPositionInfoSource () |
| virtual void | setUpdateInterval (int msec) |
| int | updateInterval () const |
| virtual void | setPreferredPositioningMethods (PositioningMethods methods) |
| PositioningMethods | preferredPositioningMethods () const |
| QGeoPositionInfo | lastKnownPosition (bool fromSatellitePositioningMethodsOnly=false) const =0 |
| PositioningMethods | supportedPositioningMethods () const =0 |
| int | minimumUpdateInterval () const =0 |
Static Public Functions Index
| QGeoPositionInfoSource * | createDefaultSource (QObject *parent) |
| QGeoPositionInfoSource * | createSource (const QString &sourceName, QObject *parent) |
| QStringList | availableSources () |
Public Slots Index
| void | startUpdates ()=0 |
| void | stopUpdates ()=0 |
| void | requestUpdate (int timeout=0)=0 |
Signals Index
| void | positionUpdated (const QGeoPositionInfo &update) |
| void | updateTimeout () |
Public Types
Defines the types of positioning methods.
SatellitePositioningMethods Satellite-based positioning methods such as GPS. NonSatellitePositioningMethods Other positioning methods. AllPositioningMethods A flag that matches all positioning methods.
- SatellitePositioningMethods = 0x000000ff
- NonSatellitePositioningMethods = 0xffffff00
- AllPositioningMethods = 0xffffffff
Properties
int
This property holds the requested interval in milliseconds between each update.
If the update interval is not set (or is set to 0) the source will provide updates as often as necessary.
If the update interval is set, the source will provide updates at an interval as close to the requested interval as possible. If the requested interval is less than the minimumUpdateInterval(), the minimum interval is used instead.
Changes to the update interval will happen as soon as is practical, however the time the change takes may vary between implementations. Whether or not the elapsed time from the previous interval is counted as part of the new interval is also implementation dependent.
The default value for this property is 0.
Note: Subclass implementations must call the base implementation of setUpdateInterval() so that updateInterval() returns the correct value.
int
This property holds the minimum time (in milliseconds) required to retrieve a position update.
This is the minimum value accepted by setUpdateInterval() and requestUpdate().
Public Functions
Creates a position source with the specified parent.
virtual
Destructor.
virtual void
int
virtual void
Sets the preferred positioning methods for this source to methods.
If methods includes a method that is not supported by the source, the unsupported method will be ignored.
If methods does not include any methods supported by the source, the preferred methods will be set to the set of methods which the source supports.
{Note:} When reimplementing this method, subclasses must call the base method implementation to ensure preferredPositioningMethods() returns the correct value.
PositioningMethods
Returns the positioning methods set by setPreferredPositioningMethods().
QGeoPositionInfo
Returns an update containing the last known position, or a null update if none is available.
If fromSatellitePositioningMethodsOnly is true, this returns the last known position received from a satellite positioning method; if none is available, a null update is returned.
PositioningMethods
Returns the positioning methods available to this source.
int
Static Public Functions
QGeoPositionInfoSource *
Creates and returns a position source with the given parent that reads from the system's default sources of location data, or the plugin with the highest available priority.
Returns 0 if the system has no default position source and no valid plugins could be found.
QGeoPositionInfoSource *
Creates and returns a position source with the given parent, by loading the plugin named sourceName.
Returns 0 if the plugin cannot be found.
QStringList
Returns a list of available source plugins.
Note that this list does not include the default platform backend, if one is available.
Public Slots
void
Starts emitting updates at regular intervals as specified by setUpdateInterval().
If setUpdateInterval() has not been called, the source will emit updates as soon as they become available.
An updateTimout() signal will be emitted if this QGeoPositionInfoSource subclass determines that it will not be able to provide regular updates. This could happen if a satellite fix is lost or if a hardware error is detected. Position updates will recommence if the data becomes available later on. The updateTimout() signal will not be emitted again until after the periodic updates resume.
Note on BlackBerry there are some situations where position updates will not recommence after an updateTimeout() signal is emitted. These situations can be identified in the slot connected to updateTimeout() using the replyErrorCode property of the BlackBerry QGeoPositionInfoSource instance.
void
Stops emitting updates at regular intervals.
void
Attempts to get the current position and emit positionUpdated() with this information.
If the current position cannot be found within the given timeout (in milliseconds) or if timeout is less than the value returned by minimumUpdateInterval(), updateTimeout() is emitted.
If the timeout is zero, the timeout defaults to a reasonable timeout period as appropriate for the source.
This does nothing if another update request is in progress. However it can be called even if startUpdates() has already been called and regular updates are in progress.
If the source uses multiple positioning methods, it tries to get the current position from the most accurate positioning method within the given timeout.
Note that on BlackBerry updateTimeout() may be emitted for other reasons, such as the app's permission to access location services being disabled. These situations can be identified in the slot connected to updateTimeout() using the replyErrorCode property of the BlackBerry QGeoPositionInfoSource instance.
Signals
void
If startUpdates() or requestUpdate() is called, this signal is emitted when an update becomes available.
The update value holds the value of the new update.
void
If requestUpdate() was called, this signal will be emitted if the current position could not be retrieved within the specified timeout.
If startUpdates() has been called, this signal will be emitted if this QGeoPositionInfoSource subclass determines that it will not be able to provide further regular updates. This signal will not be emitted again until after the regular updates resume.
© 2008-2011 Nokia Corporation and/or its subsidiaries. Nokia, Qt and their respective logos are trademarks of Nokia Corporation in Finland and/or other countries worldwide. All other trademarks are property of their respective owners. Privacy Policy
Licensees holding valid Qt Commercial licenses may use this document in accordance with the Qt Commercial License Agreement provided with the Software or, alternatively, in accordance with the terms contained in a written agreement between you and Nokia. Alternatively, this document may be used under the terms of the GNU Free Documentation License version 1.3 as published by the Free Software Foundation.