Skip to content

Commit 3acb6b6

Browse files
committed
Merge branch 'main' into feature/android_secondary_position_stream
2 parents bf1cd25 + ce4b3a7 commit 3acb6b6

File tree

153 files changed

+1118
-683
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

153 files changed

+1118
-683
lines changed

.github/workflows/geolocator.yaml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,11 +33,11 @@ jobs:
3333
# Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it
3434
- uses: actions/checkout@v4
3535

36-
# Ensures JAVA 11 is installed on the build agent.
36+
# Ensures JAVA 17 is installed on the build agent.
3737
- uses: actions/setup-java@v4
3838
with:
3939
distribution: 'temurin'
40-
java-version: '11'
40+
java-version: '17'
4141

4242
# Make sure the stable version of Flutter is available
4343
- uses: subosito/flutter-action@v2
@@ -49,8 +49,8 @@ jobs:
4949
run: flutter pub get
5050
working-directory: ${{env.source-directory}}
5151

52-
# Run Flutter Format to ensure formatting is valid
53-
- name: Run Flutter Format
52+
# Run Dart Format to ensure formatting is valid
53+
- name: Run Dart Format
5454
run: dart format --set-exit-if-changed .
5555
working-directory: ${{env.source-directory}}
5656

.github/workflows/geolocator_android.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ jobs:
3737
- uses: actions/setup-java@v4
3838
with:
3939
distribution: 'temurin'
40-
java-version: '11'
40+
java-version: '17'
4141

4242
# Make sure the stable version of Flutter is available
4343
- uses: subosito/flutter-action@v2

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ unlinked.ds
5858
unlinked_spec.ds
5959
flutter_export_environment.sh
6060
**/.flutter-plugins-dependencies
61+
**/Flutter/ephemeral/
6162

6263
# Android related
6364
gradle-wrapper.jar
@@ -95,6 +96,8 @@ GeneratedPluginRegistrant.java
9596
**/ios/ServiceDefinitions.json
9697
**/ios/Runner/GeneratedPluginRegistrant.*
9798
**/ios/Flutter/Flutter.podspec
99+
**/.build/
100+
**/.swiftpm/
98101

99102
# Firebase related
100103
.firebase/

CONTRIBUTING.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ We really appreciate contributions via GitHub pull requests. To contribute take
3636
* `git checkout upstream/develop -b <name_of_your_branch>`
3737
* Apply your changes
3838
* Verify your changes and fix potential warnings/ errors:
39-
* Check formatting: `flutter format .`
39+
* Check formatting: `dart format .`
4040
* Run static analyses: `flutter analyze`
4141
* Run unit-tests: `flutter test`
4242
* Commit your changes: `git commit -am "<your informative commit message>"`
@@ -46,4 +46,4 @@ Send us your pull request:
4646

4747
* Go to `https://github.com/BaseflowIT/flutter-geolocator` and click the "Compare & pull request" button.
4848

49-
Please make sure you solved all warnings and errors reported by the static code analyses and that you fill in the full pull request template. Failing to do so will result in us asking you to fix it.
49+
Please make sure you solved all warnings and errors reported by the static code analyses and that you fill in the full pull request template. Failing to do so will result in us asking you to fix it.

geolocator/CHANGELOG.md

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,54 @@
1+
## NEXT
2+
3+
- Adds section about `UIBackgroundModes` to the README.
4+
5+
## 14.0.1
6+
7+
- Adds section about `FOREGROUND_SERVICE_LOCATION` to the README.
8+
- Fixes PlatformException in example app for Android 14 (SDK level 34) and newer by updating manifest permissions.
9+
10+
## 14.0.0
11+
12+
- **BREAKING CHANGE:** for Flutter `3.27.0` and below. Make sure you'll upgrade Flutter to `3.29.0` or above before using this version.
13+
- Bump `flutter_lints` to version of afp to 5.0.0
14+
- Updated `geolocator_android` dependency to version `^5.0.0`
15+
16+
## 13.0.4
17+
18+
- Bump `flutter_lints` to version 5.0.0. Later added: of afp example project.
19+
20+
## 13.0.3
21+
22+
- Updates dart sdk to `sdk: ^3.5.0`
23+
- Updates example project and fixes analyzer issues
24+
25+
## 13.0.2
26+
27+
- Updates dependency on geolocator_apple to version 2.3.8.
28+
- Migrates Android configuration of example app away from imperative gradle API.
29+
30+
## 13.0.1
31+
32+
- Resolves problems when compiling non-web platforms because of illegal reference to `dart:js_interop`.
33+
34+
## 13.0.0
35+
36+
- **BREAKING CHANGE:** Deprecates getCurrentPosition desiredAccuracy, forceAndroidLocationManager, and timeLimit parameters in favor of supplying a LocationSettings class.
37+
- Exposes `WebSettings` from geolocator.
38+
- Updates dependency on geolocator_web to version 4.1.0
39+
- Updates dependency on geolocator_android to version 4.3.0
40+
- Updates dependency on geolocator_apple to version 2.3.7
41+
- Updates dependency on geolocator_windows to version 0.2.3
42+
- Updates dependency on geolocator_platform_interface to version 4.2.3
43+
44+
## 12.0.0
45+
46+
- **BREAKING CHANGE:** Updates dependency on geolocator_web to version [4.0.0](https://pub.dev/packages/geolocator_web/changelog).
47+
48+
## 11.1.0
49+
50+
- Expose `AndroidPosition` from geolocator.
51+
152
## 11.0.0
253

354
- **BREAKING CHANGE:** Updates dependency on geolocator_web to version [3.0.0](https://pub.dev/packages/geolocator_web/changelog).

geolocator/README.md

Lines changed: 54 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -42,11 +42,11 @@ The TL;DR version is:
4242
android.useAndroidX=true
4343
android.enableJetifier=true
4444
```
45-
2. Make sure you set the `compileSdkVersion` in your "android/app/build.gradle" file to 33:
45+
2. Make sure you set the `compileSdkVersion` in your "android/app/build.gradle" file to 35:
4646

4747
```
4848
android {
49-
compileSdkVersion 33
49+
compileSdkVersion 35
5050
5151
...
5252
}
@@ -62,12 +62,19 @@ On Android you'll need to add either the `ACCESS_COARSE_LOCATION` or the `ACCESS
6262
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
6363
```
6464

65-
Starting from Android 10 you need to add the `ACCESS_BACKGROUND_LOCATION` permission (next to the `ACCESS_COARSE_LOCATION` or the `ACCESS_FINE_LOCATION` permission) if you want to continue receiving updates even when your App is running in the background (note that the geolocator plugin doesn't support receiving and processing location updates while running in the background):
65+
Starting from Android 10 you need to add the `ACCESS_BACKGROUND_LOCATION` permission (next to the `ACCESS_COARSE_LOCATION` or the `ACCESS_FINE_LOCATION` permission) if you want to continue receiving updates even when your App is running in the background:
6666

6767
``` xml
6868
<uses-permission android:name="android.permission.ACCESS_BACKGROUND_LOCATION" />
6969
```
7070

71+
Starting from Android 14 (SDK 34) you need to add the `FOREGROUND_SERVICE_LOCATION` permission (next to the `ACCESS_COARSE_LOCATION` or the `ACCESS_FINE_LOCATION` or the `ACCESS_BACKGROUND_LOCATION` permission) if you want to continue receiving updates even when your App is running in the foreground:
72+
[FOREGROUND_SERVICE_LOCATION](https://developer.android.com/reference/android/Manifest.permission#FOREGROUND_SERVICE_LOCATION)
73+
74+
``` xml
75+
<uses-permission android:name="android.permission.FOREGROUND_SERVICE_LOCATION"
76+
```
77+
7178
> **NOTE:** Specifying the `ACCESS_COARSE_LOCATION` permission results in location updates with an accuracy approximately equivalent to a city block. It might take a long time (minutes) before you will get your first locations fix as `ACCESS_COARSE_LOCATION` will only use the network services to calculate the position of the device. More information can be found [here](https://developer.android.com/training/location/retrieve-current#permissions).
7279

7380

@@ -76,7 +83,7 @@ Starting from Android 10 you need to add the `ACCESS_BACKGROUND_LOCATION` permis
7683
<details>
7784
<summary>iOS</summary>
7885

79-
On iOS you'll need to add the following entry to your Info.plist file (located under ios/Runner) in order to access the device's location. Simply open your Info.plist file and add the following (make sure you update the description so it is meaningfull in the context of your App):
86+
On iOS you'll need to add the following entry to your Info.plist file (located under ios/Runner) in order to access the device's location. Simply open your Info.plist file and add the following (make sure you update the description so it is meaningful in the context of your App):
8087

8188
``` xml
8289
<key>NSLocationWhenInUseUsageDescription</key>
@@ -116,6 +123,15 @@ The second key (in this example called `YourPurposeKey`) should match the purpos
116123
> NOTE: the first time requesting temporary full accuracy access it might take several seconds for the pop-up to show. This is due to the fact that iOS is determining the exact user location which may take several seconds. Unfortunately this is out of our hands.
117124
</details>
118125
126+
On iOS 16 and above you need to specify `UIBackgroundModes` `location` to receive location updates in the background.
127+
128+
``` xml
129+
<key>UIBackgroundModes</key>
130+
<array>
131+
<string>location</string>
132+
</array>
133+
```
134+
119135
<details>
120136
<summary>macOS</summary>
121137

@@ -228,12 +244,17 @@ Future<Position> _determinePosition() async {
228244
To query the current location of the device simply make a call to the `getCurrentPosition` method. You can finetune the results by specifying the following parameters:
229245

230246
- `desiredAccuracy`: the accuracy of the location data that your app wants to receive;
231-
- `timeLimit`: the maximum amount of time allowed to acquire the current location. When the time limit is passed a `TimeOutException` will be thrown and the call will be cancelled. By default no limit is configured.
247+
- `timeLimit`: the maximum amount of time allowed to acquire the current location. When the time limit is passed a `TimeoutException` will be thrown and the call will be cancelled. By default no limit is configured.
232248

233249
``` dart
234250
import 'package:geolocator/geolocator.dart';
235251
236-
Position position = await Geolocator.getCurrentPosition(desiredAccuracy: LocationAccuracy.high);
252+
final LocationSettings locationSettings = LocationSettings(
253+
accuracy: LocationAccuracy.high,
254+
distanceFilter: 100,
255+
);
256+
257+
Position position = await Geolocator.getCurrentPosition(locationSettings: locationSettings);
237258
```
238259

239260
#### Last known location
@@ -252,7 +273,7 @@ To listen for location changes you can call the `getPositionStream` to receive s
252273

253274
- `accuracy`: the accuracy of the location data that your app wants to receive;
254275
- `distanceFilter`: the minimum distance (measured in meters) a device must move horizontally before an update event is generated;
255-
- `timeLimit`: the maximum amount of time allowed between location updates. When the time limit is passed a `TimeOutException` will be thrown and the stream will be cancelled. By default no limit is configured.
276+
- `timeLimit`: the maximum amount of time allowed between location updates. When the time limit is passed a `TimeoutException` will be thrown and the stream will be cancelled. By default no limit is configured.
256277

257278
``` dart
258279
import 'package:geolocator/geolocator.dart';
@@ -267,29 +288,32 @@ StreamSubscription<Position> positionStream = Geolocator.getPositionStream(locat
267288
});
268289
```
269290

270-
In certain situation it is necessary to specify some platform specific settings. This can be accomplished using the platform specific `AndroidSettings` or `AppleSettings` classes. When using a platform specific class, the platform specific package must be imported as well. For example:
291+
### Platform specific location settings
292+
293+
In certain situation it is necessary to specify some platform specific settings. This can be accomplished using the platform specific `AndroidSettings`, `AppleSettings` and `WebSettings` classes. When using a platform specific class, the platform specific package must be imported as well. For example:
271294

272295
```dart
273296
import 'package:geolocator/geolocator.dart';
274-
import 'package:geolocator_apple/geolocator_apple.dart';
275297
import 'package:geolocator_android/geolocator_android.dart';
298+
import 'package:geolocator_android/geolocator_web.dart';
299+
import 'package:geolocator_apple/geolocator_apple.dart';
276300
277301
late LocationSettings locationSettings;
278302
279303
if (defaultTargetPlatform == TargetPlatform.android) {
280304
locationSettings = AndroidSettings(
281-
accuracy: LocationAccuracy.high,
282-
distanceFilter: 100,
283-
forceLocationManager: true,
284-
intervalDuration: const Duration(seconds: 10),
285-
//(Optional) Set foreground notification config to keep the app alive
286-
//when going to the background
287-
foregroundNotificationConfig: const ForegroundNotificationConfig(
305+
accuracy: LocationAccuracy.high,
306+
distanceFilter: 100,
307+
forceLocationManager: true,
308+
intervalDuration: const Duration(seconds: 10),
309+
//(Optional) Set foreground notification config to keep the app alive
310+
//when going to the background
311+
foregroundNotificationConfig: const ForegroundNotificationConfig(
288312
notificationText:
289313
"Example app will continue to receive your location even when you aren't using it",
290314
notificationTitle: "Running in Background",
291315
enableWakeLock: true,
292-
)
316+
)
293317
);
294318
} else if (defaultTargetPlatform == TargetPlatform.iOS || defaultTargetPlatform == TargetPlatform.macOS) {
295319
locationSettings = AppleSettings(
@@ -300,16 +324,26 @@ if (defaultTargetPlatform == TargetPlatform.android) {
300324
// Only set to true if our app will be started up in the background.
301325
showBackgroundLocationIndicator: false,
302326
);
327+
} else if (kIsWeb) {
328+
locationSettings = WebSettings(
329+
accuracy: LocationAccuracy.high,
330+
distanceFilter: 100,
331+
maximumAge: Duration(minutes: 5),
332+
);
303333
} else {
304-
locationSettings = LocationSettings(
334+
locationSettings = LocationSettings(
305335
accuracy: LocationAccuracy.high,
306336
distanceFilter: 100,
307337
);
308338
}
309339
340+
// supply location settings to getCurrentPosition
341+
Position position = await Geolocator.getCurrentPosition(locationSettings: locationSettings);
342+
343+
// supply location settings to getPositionStream
310344
StreamSubscription<Position> positionStream = Geolocator.getPositionStream(locationSettings: locationSettings).listen(
311-
(Position? position) {
312-
print(position == null ? 'Unknown' : '${position.latitude.toString()}, ${position.longitude.toString()}');
345+
(Position? position) {
346+
print(position == null ? 'Unknown' : '${position.latitude.toString()}, ${position.longitude.toString()}');
313347
});
314348
```
315349

geolocator/example/android/app/build.gradle

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
plugins {
2+
id "com.android.application"
3+
id "dev.flutter.flutter-gradle-plugin"
4+
}
5+
16
def localProperties = new Properties()
27
def localPropertiesFile = rootProject.file('local.properties')
38
if (localPropertiesFile.exists()) {
@@ -6,11 +11,6 @@ if (localPropertiesFile.exists()) {
611
}
712
}
813

9-
def flutterRoot = localProperties.getProperty('flutter.sdk')
10-
if (flutterRoot == null) {
11-
throw new GradleException("Flutter SDK not found. Define location with flutter.sdk in the local.properties file.")
12-
}
13-
1414
def flutterVersionCode = localProperties.getProperty('flutter.versionCode')
1515
if (flutterVersionCode == null) {
1616
flutterVersionCode = '1'
@@ -27,18 +27,15 @@ project.getTasks().withType(JavaCompile) {
2727
options.compilerArgs.addAll(args)
2828
}
2929

30-
apply plugin: 'com.android.application'
31-
apply from: "$flutterRoot/packages/flutter_tools/gradle/flutter.gradle"
32-
3330
android {
34-
compileSdkVersion 33
31+
compileSdkVersion flutter.compileSdkVersion
3532

3633

3734
defaultConfig {
3835
// TODO: Specify your own unique Application ID (https://developer.android.com/studio/build/application-id.html).
3936
applicationId "com.baseflow.geolocator_example"
40-
minSdkVersion 16
41-
targetSdkVersion 30
37+
minSdkVersion flutter.minSdkVersion
38+
targetSdkVersion flutter.targetSdkVersion
4239
versionCode flutterVersionCode.toInteger()
4340
versionName flutterVersionName
4441
}

geolocator/example/android/app/src/main/AndroidManifest.xml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88

99
<!-- Permissions options for the `location` group -->
1010
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
11+
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
12+
<uses-permission android:name="android.permission.FOREGROUND_SERVICE_LOCATION" />
1113

1214
<application
1315
android:name="${applicationName}"
@@ -19,7 +21,8 @@
1921
android:theme="@style/LaunchTheme"
2022
android:configChanges="orientation|keyboardHidden|keyboard|screenSize|smallestScreenSize|locale|layoutDirection|fontScale|screenLayout|density|uiMode"
2123
android:hardwareAccelerated="true"
22-
android:windowSoftInputMode="adjustResize">
24+
android:windowSoftInputMode="adjustResize"
25+
android:exported="true">
2326
<!-- Specifies an Android theme to apply to this Activity as soon as
2427
the Android process has started. This theme is visible to the user
2528
while the Flutter UI initializes. After that, this theme continues
Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,3 @@
1-
buildscript {
2-
repositories {
3-
google()
4-
mavenCentral()
5-
}
6-
7-
dependencies {
8-
classpath 'com.android.tools.build:gradle:7.1.2'
9-
}
10-
}
11-
121
allprojects {
132
repositories {
143
google()
@@ -24,6 +13,6 @@ subprojects {
2413
project.evaluationDependsOn(':app')
2514
}
2615

27-
task clean(type: Delete) {
16+
tasks.register("clean", Delete) {
2817
delete rootProject.buildDir
2918
}

geolocator/example/android/gradle/wrapper/gradle-wrapper.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,4 @@ distributionBase=GRADLE_USER_HOME
33
distributionPath=wrapper/dists
44
zipStoreBase=GRADLE_USER_HOME
55
zipStorePath=wrapper/dists
6-
distributionUrl=https\://services.gradle.org/distributions/gradle-7.2-all.zip
6+
distributionUrl=https\://services.gradle.org/distributions/gradle-8.9-all.zip

0 commit comments

Comments
 (0)