Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,15 @@ void requestIgnoreBatteryOptimizations()
static void checkGPSEnabled()
{
LocationManager locationManager = (LocationManager) instance.getSystemService(LOCATION_SERVICE);
boolean enabled = locationManager.isProviderEnabled(LocationManager.GPS_PROVIDER);
// Use isLocationEnabled() for API 28 or higher to check if location services are enabled at all,
// on lower API levels check if either GPS or Network provider is enabled to cover devices without GPS (mocked with external device).
boolean enabled;
if (Build.VERSION.SDK_INT >= 28) {
enabled = locationManager.isLocationEnabled();
} else {
enabled = locationManager.isProviderEnabled(LocationManager.GPS_PROVIDER)
|| locationManager.isProviderEnabled(LocationManager.NETWORK_PROVIDER);
}
if (!enabled)
{
instance.runOnUiThread(new Runnable() {
Expand Down
6 changes: 4 additions & 2 deletions src/sensors/gps_display.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,8 @@ GPSDisplay::GPSDisplay(MapWidget* widget, const Georeferencing& georeferencing,
return;
}

source->setPreferredPositioningMethods(QGeoPositionInfoSource::SatellitePositioningMethods);
// Use all available positioning methods to cover devices without GPS (mocked with external device)
source->setPreferredPositioningMethods(QGeoPositionInfoSource::AllPositioningMethods);
source->setUpdateInterval(1000);
connect(source, &QGeoPositionInfoSource::positionUpdated, this, &GPSDisplay::positionUpdated, Qt::QueuedConnection);
connect(source, QOverload<QGeoPositionInfoSource::Error>::of(&QGeoPositionInfoSource::error), this, &GPSDisplay::error);
Expand Down Expand Up @@ -438,7 +439,8 @@ MapCoordF GPSDisplay::calcLatestGPSCoord(bool& ok)
return latest_gps_coord;
}

const auto latest_pos_info = source->lastKnownPosition(true);
// Get latest position info from any source
const auto latest_pos_info = source->lastKnownPosition(false);
latest_gps_coord_accuracy = latest_pos_info.hasAttribute(QGeoPositionInfo::HorizontalAccuracy)
? float(latest_pos_info.attribute(QGeoPositionInfo::HorizontalAccuracy))
: -1;
Expand Down