2
2
3
3
[ ![ pub package] ( https://img.shields.io/pub/v/geolocation.svg )] ( https://pub.dartlang.org/packages/geolocation )
4
4
5
- Flutter [ geolocation plugin] ( https://pub.dartlang.org/packages/geolocation/ ) for Android API 16+ and iOS 9+.
5
+ Flutter [ geolocation plugin] ( https://pub.dartlang.org/packages/geolocation/ ) for Android API 16+ and iOS 9+.
6
6
7
7
Features:
8
8
9
- * Manual and automatic location permission management
10
- * Current one-shot location
11
- * Continuous location updates with foreground and background options
9
+ - Manual and automatic location permission management
10
+ - Current one-shot location
11
+ - Continuous location updates with foreground and background options
12
12
13
13
The plugin is under active development and the following features are planned soon:
14
14
15
- * Geocode
16
- * Geofences
17
- * Place suggestions
18
- * Activity recognition
19
- * Exposition of iOS/Android specific APIs (like significant location updates on iOS)
20
-
21
-
22
- Android | iOS
23
- :---: | :---:
24
- ![ ] ( https://github.com/loup-v/geolocation/blob/master/doc/android_screenshot.jpg?raw=true ) | ![ ] ( https://github.com/loup-v/geolocation/blob/master/doc/ios_screenshot.jpg?raw=true )
15
+ - Geocode
16
+ - Geofences
17
+ - Place suggestions
18
+ - Activity recognition
19
+ - Exposition of iOS/Android specific APIs (like significant location updates on iOS)
25
20
21
+ | Android | iOS |
22
+ | :----------------------------------------------------------------------------------------: | :------------------------------------------------------------------------------------: |
23
+ | ![ ] ( https://github.com/loup-v/geolocation/blob/master/doc/android_screenshot.jpg?raw=true ) | ![ ] ( https://github.com/loup-v/geolocation/blob/master/doc/ios_screenshot.jpg?raw=true ) |
26
24
27
25
## Installation
28
26
29
27
Add geolocation to your pubspec.yaml:
30
28
31
29
``` yaml
32
30
dependencies :
33
- geolocation :
34
- git :
35
- url : https://github.com/loup-v/geolocation
31
+ geolocation : ^1.0.0
36
32
` ` `
37
33
38
34
## Import
@@ -44,19 +40,20 @@ import 'package:geolocation/geolocation.dart';
44
40
```
45
41
46
42
** Note:** There is a known issue for integrating swift written plugin into Flutter project created with Objective-C template.
47
- See issue [ Flutter #16049 ] ( https://github.com/flutter/flutter/issues/16049 ) for help on integration.
48
-
43
+ See issue [ Flutter #16049 ] ( https://github.com/flutter/flutter/issues/16049 ) for help on integration.
49
44
50
45
### AndroidX Requirement
46
+
51
47
You may need to updated your '/android/gradle.properties' to include use of AndroidX.
48
+
52
49
```
53
50
android.useAndroidX=true
54
51
android.enableJetifier=true
55
52
```
56
53
57
54
### Permission
58
55
59
- Android and iOS require to declare the location permission in a configuration file.
56
+ Android and iOS require to declare the location permission in a configuration file.
60
57
61
58
#### For iOS
62
59
@@ -74,15 +71,14 @@ You need to declare the description for the desired permission in `ios/Runner/In
74
71
<string >Reason why app needs location</string >
75
72
<key >NSLocationAlwaysAndWhenInUseUsageDescription</key >
76
73
<string >Reason why app needs location</string >
77
-
74
+
78
75
<!-- additionally for iOS 9/10, if you need always permission -->
79
76
<key >NSLocationAlwaysUsageDescription</key >
80
77
<string >Reason why app needs location</string >
81
78
...
82
79
</dict >
83
80
```
84
81
85
-
86
82
#### For Android
87
83
88
84
There are two kinds of location permission in Android: "coarse" and "fine".
@@ -96,10 +92,9 @@ You need to declare one of the two permissions in `android/app/src/main/AndroidM
96
92
<!-- or -->
97
93
<uses-permission android : name =" android.permission.ACCESS_FINE_LOCATION" />
98
94
</manifest >
99
- ```
100
-
101
- Note that ` ACCESS_FINE_LOCATION ` permission includes ` ACCESS_COARSE_LOCATION ` .
95
+ ```
102
96
97
+ Note that ` ACCESS_FINE_LOCATION ` permission includes ` ACCESS_COARSE_LOCATION ` .
103
98
104
99
## API
105
100
@@ -119,13 +114,13 @@ if(result.isSuccessful) {
119
114
} else {
120
115
// location service is not enabled, restricted, or location permission is denied
121
116
}
122
- ```
117
+ ```
123
118
124
119
### Request location permission
125
120
126
121
On Android (api 23+) and iOS, geolocation needs to request permission at runtime.
127
122
128
- _ Note: You are not required to request permission manually.
123
+ _ Note: You are not required to request permission manually.
129
124
Geolocation plugin will request permission automatically if it's needed, when you make a location request._
130
125
131
126
API documentation: https://pub.dartlang.org/documentation/geolocation/0.2.1/geolocation/Geolocation/requestLocationPermission.html
@@ -140,22 +135,20 @@ if(result.isSuccessful) {
140
135
// location permission is granted (or was already granted before making the request)
141
136
} else {
142
137
// location permission is not granted
143
- // user might have denied, but it's also possible that location service is not enabled, restricted, and user never saw the permission request dialog
138
+ // user might have denied, but it's also possible that location service is not enabled, restricted, and user never saw the permission request dialog
144
139
}
145
- ```
146
-
140
+ ```
147
141
148
142
### Get the current one-shot location
149
143
150
144
Geolocation offers three methods:
151
145
152
- * Last known location (best on Android):
153
- https://pub.dartlang.org/documentation/geolocation/0.2.1/geolocation/Geolocation/lastKnownLocation.html
154
- * Single location update (best on iOS):
155
- https://pub.dartlang.org/documentation/geolocation/0.2.1/geolocation/Geolocation/singleLocationUpdate.html
156
- * Current location (best of both worlds, tries to retrieve last known location on Android, otherwise requests a single location update):
157
- https://pub.dartlang.org/documentation/geolocation/0.2.1/geolocation/Geolocation/currentLocation.html
158
-
146
+ - Last known location (best on Android):
147
+ https://pub.dartlang.org/documentation/geolocation/0.2.1/geolocation/Geolocation/lastKnownLocation.html
148
+ - Single location update (best on iOS):
149
+ https://pub.dartlang.org/documentation/geolocation/0.2.1/geolocation/Geolocation/singleLocationUpdate.html
150
+ - Current location (best of both worlds, tries to retrieve last known location on Android, otherwise requests a single location update):
151
+ https://pub.dartlang.org/documentation/geolocation/0.2.1/geolocation/Geolocation/currentLocation.html
159
152
160
153
``` dart
161
154
// best option for most cases
@@ -175,7 +168,6 @@ StreamSubscription<LocationResult> subscription = Geolocation.currentLocation(ac
175
168
LocationResult result = await Geolocation.lastKnownLocation();
176
169
```
177
170
178
-
179
171
### Continuous location updates
180
172
181
173
API documentation: https://pub.dartlang.org/documentation/geolocation/0.2.1/geolocation/Geolocation/locationUpdates.html
@@ -184,7 +176,7 @@ API documentation: https://pub.dartlang.org/documentation/geolocation/0.2.1/geol
184
176
StreamSubscription<LocationResult> subscription = Geolocation.locationUpdates(
185
177
accuracy: LocationAccuracy.best,
186
178
displacementFilter: 10.0, // in meters
187
- inBackground: true, // by default, location updates will pause when app is inactive (in background). Set to `true` to continue updates in background.
179
+ inBackground: true, // by default, location updates will pause when app is inactive (in background). Set to `true` to continue updates in background.
188
180
)
189
181
.listen((result) {
190
182
if(result.isSuccessful) {
@@ -197,7 +189,6 @@ StreamSubscription<LocationResult> subscription = Geolocation.locationUpdates(
197
189
subscription.cancel();
198
190
```
199
191
200
-
201
192
### Handle location result
202
193
203
194
Location request return either a ` LocationResult ` future or a stream of ` LocationResult ` .
@@ -208,7 +199,7 @@ API documentation: https://pub.dartlang.org/documentation/geolocation/0.2.1/geol
208
199
LocationResult result = await Geolocation.lastKnownLocation();
209
200
210
201
if (result.isSuccessful) {
211
- // location request successful, location is guaranteed to not be null
202
+ // location request successful, location is guaranteed to not be null
212
203
double lat = result.location.latitude;
213
204
double lng = result.location.longitude;
214
205
} else {
@@ -221,7 +212,7 @@ if (result.isSuccessful) {
221
212
break;
222
213
case GeolocationResultErrorType.serviceDisabled:
223
214
// location services disabled on device
224
- // might be that GPS is turned off, or parental control (android)
215
+ // might be that GPS is turned off, or parental control (android)
225
216
break;
226
217
case GeolocationResultErrorType.permissionDenied:
227
218
// user denied location permission request
@@ -242,21 +233,21 @@ if (result.isSuccessful) {
242
233
break;
243
234
}
244
235
}
245
- ```
246
-
236
+ ```
247
237
248
238
## Authors
249
239
250
240
Geolocation plugin is developed by Loup, a mobile development studio based in Montreal and Paris.
251
241
You can contact us at
< [email protected] >
252
242
253
243
## Contributers
254
- * lukaspili
255
- * mit-mit
256
- * shehabic-work
257
- * Abgaryan
258
- * shehabic
259
- * alfanhui
244
+
245
+ - lukaspili
246
+ - mit-mit
247
+ - shehabic-work
248
+ - Abgaryan
249
+ - shehabic
250
+ - alfanhui
260
251
261
252
## License
262
253
0 commit comments