diff options
Diffstat (limited to 'src/core/location_provider_qt.cpp')
-rw-r--r-- | src/core/location_provider_qt.cpp | 26 |
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) |