μ½λλ μμΉλ₯Ό μμ²νκ³ μ¬μ©μλ μΉμΈνλ©° μ½λλ μ€λ₯λ₯Ό λ°μμν΅λλ€.
PlatformException (PERMISSION_DENIED, μμΉ λ°μ΄ν°μ λν μ‘μΈμ€κ° κ±°λΆ λ¨, null)
κ·Έλ¬λ λ λ²μ§Έλ‘ μμΉλ₯Ό μμ²νλ©΄ λν λ μ€λ₯μμ΄ μ¬λ°λ₯Έ μμΉκ° μ¦μ λ°νλ©λλ€.
μμΉκ° λ°νλκ³ μμΉλ₯Ό μμ²νκ³ μ¬μ©μκ° μΉμΈ ν λ μ€λ₯κ° λ°μνμ§ μμ΅λλ€.
import 'package:geolocator/geolocator.dart';
try{
position = await Geolocator().getCurrentPosition(desiredAccuracy: LocationAccuracy.high);
}
catch(error)
{
print("error in geolocation: $error"); //error in geolocation: PlatformException(PERMISSION_DENIED, Access to location data denied, null)
print("position: $position"); // position: null
print("retrying"); // retrying
try{
position = await Geolocator().getCurrentPosition(desiredAccuracy: LocationAccuracy.high);
}
catch(error)
{
await printGeoStatus(5);
print("2nd error in geolocation $error");
}
print("final position: $position"); //flutter: final position: Lat: 59.xyz, Long: 17.xyz
}
Flutter λ²μ : "Channel dev, v1.5.8"
Geolocator λ²μ : ^ 4.0.2
νλ«νΌ:
@FlashJonasλ μ΅κ·Όμ geolocator
νλ¬κ·ΈμΈ (λ²μ 5.0.0)μ μμ ν 리ν©ν λ§νμΌλ©° μ΅μ λ²μ μμλμ΄ λ¬Έμ κ° κ³μ λ°μνλμ§ κΆκΈν©λλ€.
@mvanbeusekom 5.0.0μμ λ¬Έμ κ° μ¬μ ν μ‘΄μ¬ ν¨μ νμΈν©λλ€.
λ°©κΈ AppBrewery κ³Όμ μ ν΅ν΄ ν¨ν€μ§λ₯Ό λ°κ²¬νμ΅λλ€.
ν¨ν€μ§ λ¬Έμλ₯Ό λ°λ₯΄κΈ°λ‘ κ²°μ νκ³ plist νμΌμ 3 κ°μ ν€λ₯Ό μΆκ°νμ΅λλ€.
<key>NSLocationWhenInUseUsageDescription</key>
<string>This app needs access to location when open.</string>
<key>NSLocationAlwaysUsageDescription</key>
<string>This app needs access to location when in the background.</string>
<key>NSLocationAlwaysAndWhenInUseUsageDescription</key>
<string>This app needs access to location when open and in the background.</string>
첫 λ²μ§Έ μ ν
Position position = await Geolocator().getCurrentPosition(desiredAccuracy: LocationAccuracy.low);
μ¬μ©μμκ² κΆνμ μμ²ν©λλ€ (3 κ°μ§ μ ν μ¬ν ν¬ν¨) :
"μ±μ μ¬μ©νλ λμμ λ§"μ λλ₯΄λ©΄ ν°λ―Έλμ λ€μμ΄ κΈ°λ‘λ©λλ€.
[VERBOSE-2 : ui_dart_state.cc (148)] μ²λ¦¬λμ§ μμ μμΈ : PlatformException (PERMISSION_DENIED, μμΉ λ°μ΄ν°μ λν μ‘μΈμ€κ° κ±°λΆ λ¨, null)
0 Geolocator._handleInvalidPermissions (ν¨ν€μ§ : geolocator / geolocator.dart : 191 : 7)
1 Geolocator.getCurrentPosition (ν¨ν€μ§ : geolocator / geolocator.dart : 102 : 7)
2 _LoadingScreenState.getLocation (ν¨ν€μ§ : clima / screens / loading_screen.dart : 13 : 10)
3 _LoadingScreenState.build.
(ν¨ν€μ§ : clima / screens / loading_screen.dart : 23 : 13) 4 _InkResponseState._handleTap (ν¨ν€μ§ : flutter / src / material / ink_well.dart : 511 : 14)
5 _InkResponseState.build.
(ν¨ν€μ§ : flutter / src / material / ink_well.dart : 566 : 30) 6 GestureRecognizer.invokeCallback (ν¨ν€μ§ : flutter / src / gestures / recognizer.dart : 166 : 24)
7 TapGestureRecognizer._checkUp (ν¨ν€μ§ : flutter / src / gestures / tap.dart : 240 : 9)
8 TapGestureRecognizer.handlePrimaryPointer (ν¨ν€μ§ : flutter / src / gestures / tap.dart : 177 : 9)
9 <β¦>
λ λ²μ§Έ λλ¦μ μ μμ΄λ©° μμΉλ λ¬Έμ μμ΄ κΈ°λ‘λ©λλ€.
νλ¬ν° : μλ : 37.785834, λ‘± : -122.406417
μ½λ :
geolocator 5.1.2λ₯Ό μ¬μ©νμ¬ iPhone 5s, 12.2μμ μ¬μ ν λμΌν λ¬Έμ κ° μμ΅λλ€.
* νΈμ§ (Flutter Channel dev, v1.8.4)
// Called after closing welcome alert
Future getFirstLocation() async {
Position position;
try {
position = await Geolocator()
.getCurrentPosition(desiredAccuracy: LocationAccuracy.high);
} catch (error) {
print("getfirstlocation error 1");
try {
position = await Geolocator()
.getCurrentPosition(desiredAccuracy: LocationAccuracy.high);
} catch (error) {
print("error in geolocation $error");
}
}
print("getfirstlocation position: $position");
if (position != null) {
// send to database
}
}
μ μ½λλ₯Ό μ€ν ν λ‘κ·Έ :
flutter: getfirstlocation error 1
flutter: getfirstlocation position: Lat: 59.xxxx, Long: 17.yyyy
λμΌν μ€λ₯κ° λ°μν©λλ€.
Android (Oneplus 2)-Android 8.1.0-Geolocator 5.1.2
(μμΉ νκ°κ° λΆμ¬λ¨)
2019-08-15 16:54:22.606 926-1110/system_process E/InputDispatcher: channel '569829a de.paschke.coffeebreak/de.paschke.coffeebreak.MainActivity (server)' ~ Channel is unrecoverably broken and will be disposed!
2019-08-15 16:54:56.808 14735-14766/? E/flutter: [ERROR:flutter/lib/ui/ui_dart_state.cc(148)] Unhandled Exception: PlatformException(PERMISSION_DENIED, Access to location data denied, null)
#0 Geolocator._handleInvalidPermissions (package:geolocator/geolocator.dart:207:7)
#1 Geolocator.getLastKnownPosition (package:geolocator/geolocator.dart:146:7)
<asynchronous suspension>
#2 LocationService.getLastKnownLocation (package:coffee_break/services/location_service.dart:24:51)
<asynchronous suspension>
#3 UserStoreBase.checkLastLocation (package:coffee_break/stores/user_store.dart:125:36)
μΈ κ°μ§ κΆν λ¬Έμμ΄μ λͺ¨λ μ¬μ©ν λ λμΌν μ€λ₯κ° λ°μν©λλ€. NSLocationWhenInUseUsageDescription λ§ μ¬μ©νλ©΄ μ±μ΄ λ€μ μλν©λλ€. λ΄ κ°μ₯ μ’μ μΆμΈ‘μ μΈ κ°μ§ κΆνμ λͺ¨λ μ¬μ©ν λ μ±μ΄ μμλκ³ μ¬μ©μμκ² νμΈμ μμ²νκΈ° μ μ μμΉλ₯Ό 묻λ κ²μ λλ€. UI λμμ κ·Έκ²μ νμΈνλ κ²μ²λΌ 보μ΄μ§λ§ μΆμΈ‘ μΌλΏμ λλ€. μ΄μ¨λ NSLocationWhenInUseUsageDescriptionλ§μΌλ‘ μ΄ μ μλ€λ©΄ λ€λ₯Έ λ κ°λ₯Ό μ κ±°νμμμ€.
κ°μ λ¬Έμ :( flutterμ λ§μ§λ§ λ²μ μμ μ±λμμ.
μ΄ ν¨ν€μ§λ μ§μ¦λ ...
λμΌν μ€λ₯, Android 10μμ κ°μ₯ μ΅μ λ²μ μ flutter.
λλ κ°μ λ¬Έμ κ° μμ΅λλ€!
μ΄ λ¬Έμ κ° ν΄κ²° λ μ§ κΆκΈν©λλ€. 1 λ μ΄ λμκ³ μ¬λλ€μ μ¬μ ν ββμ§λ©΄νκ³ μμ΅λλ€. μ΅κ·Όμ μ λ Flutterλ₯Ό λ°°μ°κΈ° μμνκ³ μ νν λμΌν λ¨κ³λ₯Ό μ¬ννλ λμΌν λ¬Έμ λ₯Ό λ°κ²¬νμ΅λλ€.
iOS ν둬ννΈμμ "Only while using the app"μ΅μ μ μ ννλ©΄ λ λ²μ§Έλ‘ μ±μμ μμΉλ₯Ό μμ²ν΄λ μ¬λ°λ₯Έ μμΉ λ°μ΄ν°λ₯Ό μ»μλλΌλ Flutter μ½μμμ μμΈκ° λ°μν©λλ€.
μ΅μ 5.3.2+2
λ²μ μ μ¬μ©νλ PS
νμ¬μ΄ λ¬Έμ μ λν μμ μμ κ³Ό λ€λ₯Έ λ¬Έμ λͺ©λ‘μ μμ μ€μ λλ€ (μμΈν λ΄μ©μ # 430 μ°Έμ‘°). κ·Έλλ μ£Όμ μ λ°μ΄νΈκ° λ κ²μ λλ€.
νμ¬ iOS μΈ‘μ΄ μ€λΉλμμΌλ©° μ΄μ Android μΈ‘μμ μλν©λλ€.
λ²μ 6.0.0μμ μμ λμ΄μΌν©λλ€.
νμ νκΈ° λ¦μμ μλ μμ§λ§ μ±μ΄ iOSμμ κΆνμ μμ²νμ§ μκ³ Androidμμ μλ²½νκ² μλνλ λμΌν λ¬Έμ μ μ§λ©΄νμ΅λλ€.
κΆνμ μμ²νμ§ μμκΈ° λλ¬Έμ κΆν μ½λκ° iOSμμ μλνμ§ μμμ΅λλ€. μλμΌλ‘ κΆνμ μμ²νλ λ° μ¬μ©ν μμλ "location_permissions"λΌλ ν¨ν€μ§λ₯Ό μ°Ύμμ΅λλ€.
μν ν λ¨κ³λ λ€μκ³Ό κ°μ΅λλ€.
νμΌμμ ν¨ν€μ§ κ°μ Έ μ€κΈ°
import ' package : location_permissions / location_permissions.dart ';
κΆνμ μμ²νλ €λ νμ΄μ§μ λ€μ μ½λλ₯Ό μΆκ°νμμμ€. (μ±μ 첫 νμ΄μ§μ μΆκ°νλ κ²μ΄ μ’μ΅λλ€.)
<strong i="16">@override</strong>
void initState() {
....
if (Platform.isIOS) {
location_permission();
}
....
}
λμΌν νμΌμ λ€μ λ κ°μ§ λ°©λ²μ μΆκ°νμμμ€.
void location_permission () async {
μ΅μ’
PermissionStatus κΆν = λκΈ° _getLocationPermission ();
if (κΆν == PermissionStatus.granted) {
μ΅μ’
μμΉ = await geolocator.getCurrentPosition (
desiredAccuracy : LocationAccuracy.best);
// Use the position to do whatever...
}
}
λ―Έλ
μ΅μ’
PermissionStatus κΆν = await LocationPermissions ()
.checkPermissionStatus (λ 벨 : LocationPermissionLevel.location);
if (permission != PermissionStatus.granted) {
final PermissionStatus permissionStatus = await LocationPermissions()
.requestPermissions(
permissionLevel: LocationPermissionLevel.location);
return permissionStatus;
} else {
return permission;
}
}
μ΄μ iOS μ±μ μμΉ κΆνμ μμ²νλ νμ μ΄ νμλ©λλ€.
κ°μ₯ μ μ©ν λκΈ
νμ¬μ΄ λ¬Έμ μ λν μμ μμ κ³Ό λ€λ₯Έ λ¬Έμ λͺ©λ‘μ μμ μ€μ λλ€ (μμΈν λ΄μ©μ # 430 μ°Έμ‘°). κ·Έλλ μ£Όμ μ λ°μ΄νΈκ° λ κ²μ λλ€.
νμ¬ iOS μΈ‘μ΄ μ€λΉλμμΌλ©° μ΄μ Android μΈ‘μμ μλν©λλ€.