Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

NMEA Updates #1490

Merged
merged 8 commits into from
May 16, 2024
Merged
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
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'
Comment on lines +44 to +45
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am a bit afraid updating these dependencies introduce a breaking change. I have done an upgrade to version 21.1.0 of the com.google.android.gms:play-services-location which forced users to update AGP to version 8.0.0 and Kotlin to 1.9.0.

I have reverted the change as we didn't need any of the new functionality, if we do need it to support the MSL altitude we should probably update the version number to 5.0.0 and clearly mention in the CHANGELOG that users should update their Android Gradle Plugin to version 8.0.0 and Kotlin to version 1.9.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"

dev_dependencies:
async: ^2.8.2
Expand Down
Loading