-
-
Notifications
You must be signed in to change notification settings - Fork 732
Description
Please check the following before submitting a new issue.
- I have searched the existing issues.
- I have carefully read the documentation.
Please select for which platform(s) you need help
- Android
- iOS
- Linux
- macOS
- Web
- Windows
Your question
When using Geolocator.getCurrentPosition
on Android, we know that even if you have useMSLAltitude
set to true
from the AndroidSettings
, it has no effect, as stated in the Dartdoc here:
/// This property only works with position stream updates and has no effect when getting the | |
/// current position or last known position. |
However, android.location.altitude
supports an AltitudeConverter class, which does the following:
Converts altitudes reported above the World Geodetic System 1984 (WGS84) reference ellipsoid into ones above Mean Sea Level.
Is there a way AltitudeConverter
could be used by getCurrentPosition
to convert locations with WGS84 altitude into MSL? I understand that when getCurrentPosition
is called, it calls onGetCurrentPosition
, which in turn starts position updates here:
Line 241 in 756b8d8
geolocationManager.startPositionUpdates( |
My idea was something like the following (although I am no Java expert, so take with a grain of salt):
geolocationManager.startPositionUpdates(
locationClient,
activity,
(Location location) -> {
if (replySubmitted[0]) {
return;
}
replySubmitted[0] = true;
geolocationManager.stopPositionUpdates(locationClient);
pendingCurrentPositionLocationClients.remove(requestId);
// Start added code
boolean useAltitudeConverter = (boolean) map.get("useMSLAltitude");
if (useAltitudeConverter && Build.VERSION.SDK_INT >= Build.VERSION_CODES.UPSIDE_DOWN_CAKE) {
AltitudeConverter altitudeConverter = new AltitudeConverter();
boolean mslAdded = altitudeConverter.tryAddMslAltitudeToLocation(location);
if (!mslAdded) {
new Thread(() -> {
try {
altitudeConverter.addMslAltitudeToLocation(context, location);
} catch (IOException e) {
Log.e(TAG, "AltitudeConverter IOException: " + e.getMessage());
}
}).start();
}
}
// End added code
result.success(LocationMapper.toHashMap(location));
},
(ErrorCodes errorCode) -> {
if (replySubmitted[0]) {
return;
}
replySubmitted[0] = true;
geolocationManager.stopPositionUpdates(locationClient);
pendingCurrentPositionLocationClients.remove(requestId);
result.error(errorCode.toString(), errorCode.toDescription(), null);
});
In my brief testing of this it did not work. Is there any chance this could be made to work?
Version
14.0.2