diff --git a/src/android/java/org/openorienteering/mapper/MapperActivity.java b/src/android/java/org/openorienteering/mapper/MapperActivity.java index a42a95ab3..c8c7be297 100644 --- a/src/android/java/org/openorienteering/mapper/MapperActivity.java +++ b/src/android/java/org/openorienteering/mapper/MapperActivity.java @@ -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() { diff --git a/src/sensors/gps_display.cpp b/src/sensors/gps_display.cpp index 369bf5076..3023783f1 100644 --- a/src/sensors/gps_display.cpp +++ b/src/sensors/gps_display.cpp @@ -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::of(&QGeoPositionInfoSource::error), this, &GPSDisplay::error); @@ -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;