Skip to content

Commit

Permalink
NMEA Updates (#1490)
Browse files Browse the repository at this point in the history
* MSL Altitude improvements

* Fix compilation problems

* Always listen to NMEA message to get satellite fix

* Handle nullpointer edgec ases

* Formatting fixes

* fix use msl extra key

* Add change log info

---------

Co-authored-by: Maurits van Beusekom <[email protected]>
  • Loading branch information
Wackymax and mvanbeusekom authored May 16, 2024
1 parent 1bf9103 commit 6b34beb
Show file tree
Hide file tree
Showing 7 changed files with 45 additions and 15 deletions.
22 changes: 15 additions & 7 deletions geolocator_android/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
## 4.6.0

* Adds support to read NMEA messages from other satellites constellations.
* Read the MSL altitude directly from the Android location starting with API 34.
* Always listen to NMEA message to get GPS position fix data.
* Updates `com.google.android.gms:play-services-location` to version `21.2.0`.
* Updates `androidx.core:core` to version `1.13.0`.

## 4.5.5

* Fixes a bug where location stream is not automatically started when enabling the location services.
Expand Down Expand Up @@ -34,22 +42,22 @@

## 4.4.0

- Adds `color` to `ForegroundNotificationConfig` to set the color of the notification icon.
* Adds `color` to `ForegroundNotificationConfig` to set the color of the notification icon.

## 4.3.3

- Removes deprecated support for Android V1 embedding from the JAVA code base. Note that the geolocator's Flutter version restrictions already don't support V1 embedding anymore.
- Registers location services state change broadcast receiver with required exported flags
* Removes deprecated support for Android V1 embedding from the JAVA code base. Note that the geolocator's Flutter version restrictions already don't support V1 embedding anymore.
* Registers location services state change broadcast receiver with required exported flags

## 4.3.2

- Updates the following dependencies:
- uuid package from ^3.0.7 to ^4.1.0
- flutter_lints from ^2.0.0 to ^3.0.0
* Updates the following dependencies:
* uuid package from ^3.0.7 to ^4.1.0
* flutter_lints from ^2.0.0 to ^3.0.0

## 4.3.1

- Suppresses a deprecation warning for `LocationListenerCompat.onStatusChanged` when building for Android.
* Suppresses a deprecation warning for `LocationListenerCompat.onStatusChanged` when building for Android.

## 4.3.0

Expand Down
4 changes: 2 additions & 2 deletions geolocator_android/android/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,8 @@ android {
}

dependencies {
implementation 'com.google.android.gms:play-services-location:21.0.1'
implementation 'androidx.core:core:1.9.0'
implementation 'com.google.android.gms:play-services-location:21.2.0'
implementation 'androidx.core:core:1.13.0'

testImplementation 'junit:junit:4.13.2'
testImplementation 'org.mockito:mockito-core:5.1.1'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import android.content.IntentSender;
import android.location.Location;
import android.os.Build;
import android.os.Bundle;
import android.os.Looper;
import android.util.Log;

Expand Down Expand Up @@ -67,6 +68,16 @@ public synchronized void onLocationResult(@NonNull LocationResult locationResult
}

Location location = locationResult.getLastLocation();
if (location == null) {
return;
}
if (location.getExtras() == null) {
location.setExtras(Bundle.EMPTY);
}
if (locationOptions != null) {
location.getExtras().putBoolean(LocationOptions.USE_MSL_ALTITUDE_EXTRA, locationOptions.isUseMSLAltitude());
}

nmeaClient.enrichExtrasWithNmea(location);
positionChangedCallback.onPositionChanged(location);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,15 @@ public static Map<String, Object> toHashMap(Location location) {
location.getExtras().getDouble(NmeaClient.GNSS_SATELLITES_USED_IN_FIX_EXTRA);
position.put("gnss_satellites_used_in_fix", mslSatellitesUsedInFix);
}
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.UPSIDE_DOWN_CAKE && location.hasMslAltitude())
{
double mslAltitude = location.getMslAltitudeMeters();
position.put("altitude", mslAltitude);
if (location.hasMslAltitudeAccuracy()) {
float mslAccuracy = location.getMslAltitudeAccuracyMeters();
position.put("altitude_accuracy", mslAccuracy);
}
}
}
return position;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
import java.util.Map;

public class LocationOptions {
public static final String USE_MSL_ALTITUDE_EXTRA = "geolocator_use_mslAltitude";

private final LocationAccuracy accuracy;
private final long distanceFilter;
private final long timeInterval;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ public NmeaClient(@NonNull Context context, @Nullable LocationOptions locationOp
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
nmeaMessageListener =
(message, timestamp) -> {
if (message.startsWith("$GPGGA")) {
if (message.trim().matches("^\\$..GGA.*$")) {
lastNmeaMessage = message;
lastNmeaMessageTime = Calendar.getInstance();
}
Expand All @@ -71,7 +71,7 @@ public void start() {
return;
}

if (locationOptions != null && locationOptions.isUseMSLAltitude()) {
if (locationOptions != null) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N && locationManager != null) {
locationManager.addNmeaListener(nmeaMessageListener, null);
locationManager.registerGnssStatusCallback(gnssCallback, null);
Expand All @@ -81,7 +81,7 @@ public void start() {
}

public void stop() {
if (locationOptions != null && locationOptions.isUseMSLAltitude()) {
if (locationOptions != null) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N && locationManager != null) {
locationManager.removeNmeaListener(nmeaMessageListener);
locationManager.unregisterGnssStatusCallback(gnssCallback);
Expand Down Expand Up @@ -117,7 +117,7 @@ public void enrichExtrasWithNmea(@Nullable Location location) {

// Parse altitude above sea level, Detailed description of NMEA string here
// http://aprs.gids.nl/nmea/#gga
if (type.startsWith("$GPGGA") && tokens.length > 9) {
if (lastNmeaMessage.trim().matches("^\\$..GGA.*$") && tokens.length > 9) {
if (!tokens[9].isEmpty()) {
double mslAltitude = Double.parseDouble(tokens[9]);
if (location.getExtras() == null) {
Expand Down
4 changes: 2 additions & 2 deletions geolocator_android/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ name: geolocator_android
description: Geolocation plugin for Flutter. This plugin provides the Android implementation for the geolocator.
repository: https://github.com/baseflow/flutter-geolocator/tree/main/geolocator_android
issue_tracker: https://github.com/baseflow/flutter-geolocator/issues?q=is%3Aissue+is%3Aopen
version: 4.5.5
version: 4.6.0

environment:
sdk: ">=2.15.0 <4.0.0"
Expand All @@ -22,7 +22,7 @@ dependencies:
sdk: flutter
geolocator_platform_interface: ^4.1.0
meta: ^1.10.0
uuid: ^4.1.0
uuid: ">=4.0.0 <6.0.0"

This comment has been minimized.

Copy link
@cedvdb

cedvdb May 26, 2024

uuid v5 is not released yet. There is no guarantee it will be compatible here if it ever releases.


dev_dependencies:
async: ^2.8.2
Expand Down

0 comments on commit 6b34beb

Please sign in to comment.