summaryrefslogtreecommitdiffstats
path: root/src/core/location_provider_qt.cpp
diff options
context:
space:
mode:
authorJoerg Bornemann <joerg.bornemann@theqtcompany.com>2015-11-05 17:35:38 +0100
committerJoerg Bornemann <joerg.bornemann@theqtcompany.com>2015-11-09 11:13:19 +0000
commit161eba561d854c3f0125a859b40b11ba3131ea5c (patch)
tree5c79fb41de9e473b8ba62b7a3e846758f5236dbd /src/core/location_provider_qt.cpp
parentcadcec655e53819e891eb3c7b0155087d86b2688 (diff)
find high accuracy geo position source if requested
If a high accuracy geo position source is requested, iterate through all available sources and return one that supports satellite positioning methods. Change-Id: I0c76bb8f8a6502b62e3a2e012327babbab2715ad Reviewed-by: Allan Sandfeld Jensen <allan.jensen@theqtcompany.com>
Diffstat (limited to 'src/core/location_provider_qt.cpp')
-rw-r--r--src/core/location_provider_qt.cpp26
1 files changed, 23 insertions, 3 deletions
diff --git a/src/core/location_provider_qt.cpp b/src/core/location_provider_qt.cpp
index e3be01b36..222d15354 100644
--- a/src/core/location_provider_qt.cpp
+++ b/src/core/location_provider_qt.cpp
@@ -88,12 +88,15 @@ QtPositioningHelper::~QtPositioningHelper()
m_locationProvider->m_positioningHelper = 0;
}
+static bool isHighAccuracySource(const QGeoPositionInfoSource *source)
+{
+ return source->supportedPositioningMethods().testFlag(
+ QGeoPositionInfoSource::SatellitePositioningMethods);
+}
+
void QtPositioningHelper::start(bool highAccuracy)
{
DCHECK_CURRENTLY_ON(BrowserThread::UI);
- Q_UNUSED(highAccuracy);
- // FIXME: go through availableSources until one supports QGeoPositionInfoSource::SatellitePositioningMethods
- // for the highAccuracy case.
m_positionInfoSource = QGeoPositionInfoSource::createDefaultSource(this);
if (!m_positionInfoSource) {
qWarning("Failed to initialize location provider: The system either has no default "
@@ -103,6 +106,23 @@ void QtPositioningHelper::start(bool highAccuracy)
return;
}
+ // Find high accuracy source if the default source is not already one.
+ if (highAccuracy && !isHighAccuracySource(m_positionInfoSource)) {
+ Q_FOREACH (const QString &name, QGeoPositionInfoSource::availableSources()) {
+ if (name == m_positionInfoSource->sourceName())
+ continue;
+ QGeoPositionInfoSource *source = QGeoPositionInfoSource::createSource(name, this);
+ if (source && isHighAccuracySource(source)) {
+ delete m_positionInfoSource;
+ m_positionInfoSource = source;
+ break;
+ }
+ delete source;
+ }
+ m_positionInfoSource->setPreferredPositioningMethods(
+ QGeoPositionInfoSource::SatellitePositioningMethods);
+ }
+
connect(m_positionInfoSource, &QGeoPositionInfoSource::positionUpdated, this, &QtPositioningHelper::updatePosition);
// disambiguate the error getter and the signal in QGeoPositionInfoSource.
connect(m_positionInfoSource, static_cast<void (QGeoPositionInfoSource::*)(QGeoPositionInfoSource::Error)>(&QGeoPositionInfoSource::error)