QGeoPositionInfoSource Class

The QGeoPositionInfoSource class is an abstract base class for the distribution of positional updates. More...

Header: #include <QGeoPositionInfoSource>
qmake: QT += positioning
Since: Qt 5.2
Inherits: QObject
Inherited By:

QNmeaPositionInfoSource

This class was introduced in Qt 5.2.

Public Types

enum Error { AccessError, ClosedError, NoError, UnknownSourceError }
enum PositioningMethod { NoPositioningMethods, SatellitePositioningMethods, NonSatellitePositioningMethods, AllPositioningMethods }

Properties

Public Functions

virtual int minimumUpdateInterval() const = 0
virtual void setUpdateInterval(int msec)
QString sourceName() const
int updateInterval() const

Detailed Description

The static function QGeoPositionInfoSource::createDefaultSource() creates a default position source that is appropriate for the platform, if one is available. Otherwise, QGeoPositionInfoSource will check for available plugins that implement the QGeoPositionInfoSourceFactory interface.

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().

Member Type Documentation

enum QGeoPositionInfoSource::Error

The Error enumeration represents the errors which can occur.

ConstantValueDescription
QGeoPositionInfoSource::AccessError0The connection setup to the remote positioning backend failed because the application lacked the required privileges.
QGeoPositionInfoSource::ClosedError1The remote positioning backend closed the connection, which happens for example in case the user is switching location services to off. As soon as the location service is re-enabled regular updates will resume.
QGeoPositionInfoSource::NoError3No error has occurred.
QGeoPositionInfoSource::UnknownSourceError2An unidentified error occurred.

enum QGeoPositionInfoSource::PositioningMethod

Defines the types of positioning methods.

ConstantValueDescription
QGeoPositionInfoSource::NoPositioningMethods0x00000000None of the positioning methods.
QGeoPositionInfoSource::SatellitePositioningMethods0x000000ffSatellite-based positioning methods such as GPS or GLONASS.
QGeoPositionInfoSource::NonSatellitePositioningMethods0xffffff00Other positioning methods such as 3GPP cell identifier or WiFi based positioning.
QGeoPositionInfoSource::AllPositioningMethods0xffffffffSatellite-based positioning methods as soon as available. Otherwise non-satellite based methods.

Property Documentation

minimumUpdateInterval : const 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().

Access functions:

virtual int minimumUpdateInterval() const = 0

sourceName : const QString

This property holds the unique name of the position source implementation in use.

This is the same name that can be passed to createSource() in order to create a new instance of a particular position source implementation.

Access functions:

QString sourceName() const

updateInterval : 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.

Access functions:

int updateInterval() const
virtual void setUpdateInterval(int msec)