Baseflow / Baseflow/flutter-geolocator
[Question]: Possibility of using Android `AltitudeConverter` for WGS84 -> MSL
- Dominant language
- Dart
- Stars
- 1.3k
- Forks
- 803
- Avg merge
- 8h 16m
- Merged PRs (30d)
- 1
Description
### Please check the following before submitting a new issue.
- [x] I have searched the [existing issues](https://github.com/baseflow/flutter-geolocator/issues).
- [x] I have carefully [read the documentation](https://github.com/baseflow/flutter-geolocator/blob/main/geolocator/README.md).
### Please select for which platform(s) you need help
- [x] 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:
https://github.com/Baseflow/flutter-geolocator/blob/756b8d8015f06ecfcc64b438f71cb3b362b5e350/geolocator_android/lib/src/types/android_settings.dart#L68-L69
However, `android.location.altitude` supports an [AltitudeConverter](https://developer.android.com/reference/android/location/altitude/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:
https://github.com/Baseflow/flutter-geolocator/blob/756b8d8015f06ecfcc64b438f71cb3b362b5e350/geolocator_android/android/src/main/java/com/baseflow/geolocator/MethodCallHandlerImpl.java#L241
My idea was something like the following (although I am no Java expert, so take with a grain of salt):
```dart
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
Contributor guide
Research direction
Start with geolocator_android/android/src/main/java/com/baseflow/geolocator/MethodCallHandlerImpl.java, the onGetCurrentPosition flow, and the AndroidSettings Dartdoc for useMSLAltitude. Then read Android's AltitudeConverter documentation and trace when Location is mapped into the result. Done means establishing whether MSL conversion can be completed reliably before getCurrentPosition returns and defining the supported Android behavior.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- android, dart, java
- Domain
- mobile-dev
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 30/100