QGeoAreaMonitorSource Class

The QGeoAreaMonitorSource class enables the detection of proximity changes for a specified set of coordinates. More...

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

This class was introduced in Qt 5.2.

Public Types

enum AreaMonitorFeature { PersistentAreaMonitorFeature, AnyAreaMonitorFeature }
enum Error { AccessError, InsufficientPositionInfo, NoError, UnknownSourceError }

Detailed Description

A QGeoAreaMonitorSource emits signals when the current position is in range, or has moved out of range, of a specified area. Each area is specified by a QGeoAreaMonitorInfo object. For example:

 public:
     MyClass() : QObject()
     {
         QGeoAreaMonitorSource *monitor = QGeoAreaMonitorSource::createDefaultSource(this);
         if (monitor) {
             connect(monitor, SIGNAL(areaEntered(QGeoAreaMonitorInfo,QGeoPositionInfo)),
                     this, SLOT(areaEntered(QGeoAreaMonitorInfo,QGeoPositionInfo)));
             connect(monitor, SIGNAL(areaExited(QGeoAreaMonitorInfo,QGeoPositionInfo)),
                     this, SLOT(areaExited(QGeoAreaMonitorInfo,QGeoPositionInfo)));

             QGeoAreaMonitorInfo bigBen("Big Ben");
             QGeoCoordinate position(51.50104, -0.124632);
             bigBen.setArea(QGeoCircle(position, 100));

             monitor->startMonitoring(bigBen);

         } else {
             qDebug() << "Could not create default area monitor";
         }
     }

 public Q_SLOTS:
     void areaEntered(const QGeoAreaMonitorInfo &mon, const QGeoPositionInfo &update)
     {
         Q_UNUSED(mon);

         qDebug() << "Now within 100 meters, current position is" << update.coordinate();
     }

     void areaExited(const QGeoAreaMonitorInfo &mon, const QGeoPositionInfo &update)
     {
         Q_UNUSED(mon);

         qDebug() << "No longer within 100 meters, current position is" << update.coordinate();
     }

QGeoAreaMonitorSource follows a singleton pattern. Each instance of the class with the same sourceName() shares the same area monitoring backend. If a new QGeoAreaMonitorInfo object is added via startMonitoring() or requestUpdate() it can be retrieved by another instance of this class (provided that they are sourced from the same area monitor provider plug-in). The same singleton pattern applies to the QGeoPositionInfoSource instance used by this class. The following code snippet emphasizes the behavior:

 QGeoAreaMonitorSource *s1 = QGeoAreaMonitorSource::createSource("blah", this);
 QGeoAreaMonitorSource *s2 = QGeoAreaMonitorSource::createSource("blah", this);
 QVERIFY(s1->positionInfoSource() == s2->positionInfoSource);

Member Type Documentation

enum QGeoAreaMonitorSource::AreaMonitorFeature

Defines the types of area monitoring capabilities.

ConstantValueDescription
QGeoAreaMonitorSource::PersistentAreaMonitorFeature0x00000001QGeoAreaMonitorInfo instances can be made persistent. A persistent monitor continues to be active even when the application managing the monitor is not running.
QGeoAreaMonitorSource::AnyAreaMonitorFeature0xffffffffMatches all possible area monitoring features.

enum QGeoAreaMonitorSource::Error

Defines the types of positioning methods.

The Error enumeration represents the errors which can occur.

ConstantValueDescription
QGeoAreaMonitorSource::AccessError0The connection setup to the remote area monitoring backend failed because the application lacked the required privileges.
QGeoAreaMonitorSource::InsufficientPositionInfo1The area monitoring source could not retrieve a location fix or the accuracy of the fix is not high enough to provide an effective area monitoring.
QGeoAreaMonitorSource::NoError3No error has occurred.
QGeoAreaMonitorSource::UnknownSourceError2An unidentified error occurred.