Skip to content

Commit 1c097da

Browse files
author
Lukasz
committed
Update readme.
1 parent a24967a commit 1c097da

File tree

1 file changed

+27
-22
lines changed

1 file changed

+27
-22
lines changed

README.md

Lines changed: 27 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ Add geolocation to your pubspec.yaml:
3030

3131
```yaml
3232
dependencies:
33-
geolocation: ^0.2.0
33+
geolocation: ^0.2.1
3434
```
3535
3636
**Note:** There is a known issue for integrating swift written plugin into Flutter project created with Objective-C template.
@@ -48,20 +48,20 @@ There are two kinds of location permission available in iOS: "when in use" and "
4848
If you don't know what permission to choose for your usage, see:
4949
https://developer.apple.com/documentation/corelocation/choosing_the_authorization_level_for_location_services
5050
51-
You must specify the description for the desired permission in `Info.plist`:
52-
53-
*When running on iOS 9/10: `NSLocationWhenInUseUsageDescription` or `NSLocationAlwaysUsageDescription`
54-
*When running on iOS 11+: `NSLocationAlwaysAndWhenInUseUsageDescription` **and** `NSLocationWhenInUseUsageDescription`
55-
56-
You can do this via XCode, or directly by opening `io/Runner/Info.plist` in you current IDE:
51+
You need to declare the description for the desired permission in `ios/Runner/Info.plist`:
5752

5853
```xml
5954
<dict>
60-
<key>NSLocationWhenInUseUsageDescription</key>
61-
<string>Reason why app needs location</string>
62-
<key>NSLocationAlwaysAndWhenInUseUsageDescription</key>
63-
<string>Reason why app needs location</string>
64-
...
55+
<!-- for iOS 11 + -->
56+
<key>NSLocationWhenInUseUsageDescription</key>
57+
<string>Reason why app needs location</string>
58+
<key>NSLocationAlwaysAndWhenInUseUsageDescription</key>
59+
<string>Reason why app needs location</string>
60+
61+
<!-- additionally for iOS 9/10, if you need always permission -->
62+
<key>NSLocationAlwaysUsageDescription</key>
63+
<string>Reason why app needs location</string>
64+
...
6565
</dict>
6666
```
6767

@@ -87,11 +87,11 @@ Note that `ACCESS_FINE_LOCATION` permission includes `ACCESS_COARSE_LOCATION`.
8787
## API
8888

8989
For more complete documentation on all usage, check the API documentation:
90-
https://pub.dartlang.org/documentation/geolocation/0.2.0/geolocation/geolocation-library.html
90+
https://pub.dartlang.org/documentation/geolocation/0.2.1/geolocation/geolocation-library.html
9191

9292
### Check if location service is operational
9393

94-
API documentation: https://pub.dartlang.org/documentation/geolocation/0.2.0/geolocation/Geolocation/isLocationOperational.html
94+
API documentation: https://pub.dartlang.org/documentation/geolocation/0.2.1/geolocation/Geolocation/isLocationOperational.html
9595

9696
```dart
9797
final GeolocationResult result = await Geolocation.isLocationOperational();
@@ -107,12 +107,16 @@ if(result.isSuccessful) {
107107
On Android (api 23+) and iOS, geolocation needs to request permission at runtime.
108108

109109
_Note: You are not required to request permission manually.
110-
Geolocation plugin will request permission (`whenInUse` on iOS and `ACCESS_FINE_LOCATION` on Android) automatically if it's necessarily, when you make a location request._
110+
Geolocation plugin will request permission automatically if it's needed, when you make a location request._
111111

112-
API documentation: https://pub.dartlang.org/documentation/geolocation/0.2.0/geolocation/Geolocation/requestLocationPermission.html
112+
API documentation: https://pub.dartlang.org/documentation/geolocation/0.2.1/geolocation/Geolocation/requestLocationPermission.html
113113

114114
```dart
115-
final GeolocationResult result = await Geolocation.requestLocationPermission();
115+
final GeolocationResult result = await Geolocation.requestLocationPermission(const LocationPermission(
116+
android: LocationPermissionAndroid.fine,
117+
ios: LocationPermissionIOS.always,
118+
));
119+
116120
if(result.isSuccessful) {
117121
// location permission is granted (or was already granted before making the request)
118122
} else {
@@ -127,24 +131,25 @@ if(result.isSuccessful) {
127131
Geolocation offers three methods:
128132

129133
* Last known location (best on Android):
130-
https://pub.dartlang.org/documentation/geolocation/0.2.0/geolocation/Geolocation/lastKnownLocation.html
134+
https://pub.dartlang.org/documentation/geolocation/0.2.1/geolocation/Geolocation/lastKnownLocation.html
131135
* Single location update (best on iOS):
132-
https://pub.dartlang.org/documentation/geolocation/0.2.0/geolocation/Geolocation/singleLocationUpdate.html
136+
https://pub.dartlang.org/documentation/geolocation/0.2.1/geolocation/Geolocation/singleLocationUpdate.html
133137
* Current location (best of both worlds, tries to retrieve last known location on Android, otherwise requests a single location update):
134-
https://pub.dartlang.org/documentation/geolocation/0.2.0/geolocation/Geolocation/currentLocation.html
138+
https://pub.dartlang.org/documentation/geolocation/0.2.1/geolocation/Geolocation/currentLocation.html
135139

136140

137141
```dart
138142
// best option for most cases
139143
Geolocation.currentLocation(accuracy: LocationAccuracy.best).listen((result) {
140144
if(result.isSuccessful) {
141145
Double latitude = result.location.latitude;
146+
// todo with result
142147
}
143148
});
144149
145150
// force a single location update
146151
Geolocation.currentLocation(accuracy: LocationAccuracy.best).listen((result) {
147-
// to with result
152+
// todo with result
148153
});
149154
150155
// get last known location, which is a future rather than a stream
@@ -157,7 +162,7 @@ LocationResult result = await Geolocation.lastKnownLocation();
157162

158163
Location request return either a `LocationResult` future or a stream of `LocationResult`.
159164

160-
API documentation: https://pub.dartlang.org/documentation/geolocation/0.2.0/geolocation/LocationResult-class.html
165+
API documentation: https://pub.dartlang.org/documentation/geolocation/0.2.1/geolocation/LocationResult-class.html
161166

162167
```dart
163168
LocationResult result = await Geolocation.lastKnownLocation();

0 commit comments

Comments
 (0)