μμΉ κΆνμ νμ©νλ λμμλ μ λλ‘ μλνμ§λ§ μμΉ κΆνμ κ±°λΆνλ λμ λ€μ μ€λ₯κ° λ°μν©λλ€.
λ€νΈ μ€λ₯: μ²λ¦¬λμ§ μμ μμΈ:
PlatformException(PERMISSION_DENIED, μμΉ λ°μ΄ν° μ‘μΈμ€ κ±°λΆ, null)
μμ λμμ λμκ² null μλ΅μ μ 곡ν΄μΌ λ μ§νν μ μμ΅λλ€.
pubspec.yamlμμ ν κ°μ Έμ€κΈ°
λͺ¨λ λ²νΌ ν μ΄λ²€νΈμ λ€μ μ½λ μμ±
λ
Έλ ₯νλ€ {
μμΉ μμΉ = Geolocator() λκΈ°
.getCurrentPosition(desiredAccuracy: LocationAccuracy.high);
} μ‘κΈ° (e) {
μΈμ(e);
}
μ€λ₯κ° λ°μν©λλ€.
λ²μ : 1.0.1
[β] Flutter(μ±λ λ§μ€ν°, v1.0.1-pre.2, Mac OS X 10.14 18A384a, λ‘μΌμΌ en-GB)
[β] Android ν΄μ²΄μΈ - Android κΈ°κΈ°μ© κ°λ°(Android SDK 28.0.3)
[β] iOS ν΄μ²΄μΈ - iOS κΈ°κΈ°μ© κ°λ°(Xcode 10.1)
[β] μλλ‘μ΄λ μ€νλμ€(λ²μ 3.2)
[β] VS μ½λ(λ²μ 1.29.1)
[β] μ°κ²°λ μ₯μΉ(1κ° μ¬μ© κ°λ₯)
β’ λ°κ²¬λ λ¬Έμ κ° μμ΅λλ€!
νλ«νΌ:
μ΄κ±° μ΄λ»κ² ν΄κ²°νμ ¨λμ?
μ΄μ λν ν΄κ²° λ°©λ²μ΄ μμ΅λκΉ?
@YogeshLegendkiller @kaumudpa λ¬Έμ λ₯Ό ν΄κ²°νλ €λ©΄ νΈμΆμ μ‘μμ PlatformExceptionμμ nullμ λ°ννμΈμ.
@YogeshLegendkiller , @kaumudpa , @jaumard κ° μ 곡νλ μ루μ μ΄ μ΄ λ¬Έμ λ₯Ό ν΄κ²°νκΈ° μν μ μλ λ°©λ²μ λλ€.
λ λ€λ₯Έ μ κ·Ό λ°©μμ checkGeolocationPermissionStatus
λ©μλλ₯Ό μ¬μ©νκ³ getCurrentPosition
, getLastKnownPosition
λλ getPositionStream
λ₯Ό νΈμΆνκΈ° μ μ μνκ° PermissionStatus.granted
λ‘ μ€μ λμ΄ μλμ§ νμΈνλ κ²μ
λλ€ getPositionStream
λ©μλ. κ·Έλ¬λ μ΄λ μ¬μ©μκ° μ§μ κΆνμ μμ²νλ λ° μ£Όμν΄μΌ ν¨μ μλ―Έν©λλ€. μλ₯Ό λ€μ΄:
Geolocator geolocator = Geolocator();
GeolocationStatus status = await geolocator.checkGeolocationPermissionStatus();
if (status == GeolocationStatus.granted) {
Position position = await geolocator.getCurrentPosition();
}
νλ½μ ꡬνλ λ°©λ²?
@abdullah4one permission_handlerλ₯Ό μ¬μ© νκ³ λ€μκ³Ό κ°μ΄
import 'package:permission_handler/permission_handler.dart';
Map<PermissionGroup, PermissionStatus> permissions = await PermissionHandler().requestPermissions([PermissionGroup.location]);
λ΅λ³μ΄ λ¦μμ μλ μμ§λ§ iOSμμ μ±μ΄ κΆνμ μμ²νμ§ μκ³ Androidμμ μλ²½νκ² μλνλ λμΌν λ¬Έμ μ μ§λ©΄νμ΅λλ€.
κΆνμ μμ²νμ§ μμκΈ° λλ¬Έμ iOSμμ κΆν μ½λκ° μλνμ§ μμμ΅λλ€. μλμΌλ‘ κΆνμ μμ²νλ λ° μ¬μ©ν μ μλ "location_permissions"λΌλ ν¨ν€μ§λ₯Ό μ°Ύμμ΅λλ€.
μνν λ¨κ³λ λ€μκ³Ό κ°μ΅λλ€.
νμΌμμ ν¨ν€μ§ κ°μ Έμ€κΈ°
κ°μ Έμ€κΈ° ' ν¨ν€μ§:μμΉ_νκ°/μμΉ_νκ° .
κΆνμ μμ²νλ €λ νμ΄μ§μ λ€μ μ½λλ₯Ό μΆκ°ν©λλ€. (μ±μ 첫 νμ΄μ§μ μΆκ°νλ κ²μ΄ μ’μ΅λλ€.)
<strong i="16">@override</strong>
void initState() {
....
if (Platform.isIOS) {
location_permission();
}
....
}
λμΌν νμΌμ λ€μ λ κ°μ§ λ°©λ² μΆκ°
λ¬΄ν¨ location_permission() λΉλκΈ° {
μ΅μ’
PermissionStatus κΆν = await _getLocationPermission();
if (κΆν == PermissionStatus.granted) {
μ΅μ’
μμΉ = geolocator.getCurrentPosition(
μνλ μ νλ: LocationAccuracy.best);
// Use the position to do whatever...
}
}
λ―Έλ
μ΅μ’
PermissionStatus κΆν = LocationPermissions() λκΈ°
.checkPermissionStatus(λ 벨: LocationPermissionLevel.location);
if (permission != PermissionStatus.granted) {
final PermissionStatus permissionStatus = await LocationPermissions()
.requestPermissions(
permissionLevel: LocationPermissionLevel.location);
return permissionStatus;
} else {
return permission;
}
}
μ΄μ iOS μ±μμ μμΉ κΆνμ μμ²νλ νμ μ΄ νμλμ΄μΌ ν©λλ€.
κ°μ₯ μ μ©ν λκΈ
@YogeshLegendkiller , @kaumudpa , @jaumard κ° μ 곡νλ μ루μ μ΄ μ΄ λ¬Έμ λ₯Ό ν΄κ²°νκΈ° μν μ μλ λ°©λ²μ λλ€.
λ λ€λ₯Έ μ κ·Ό λ°©μμ
checkGeolocationPermissionStatus
λ©μλλ₯Ό μ¬μ©νκ³getCurrentPosition
,getLastKnownPosition
λλgetPositionStream
λ₯Ό νΈμΆνκΈ° μ μ μνκ°PermissionStatus.granted
λ‘ μ€μ λμ΄ μλμ§ νμΈνλ κ²μ λλ€getPositionStream
λ©μλ. κ·Έλ¬λ μ΄λ μ¬μ©μκ° μ§μ κΆνμ μμ²νλ λ° μ£Όμν΄μΌ ν¨μ μλ―Έν©λλ€. μλ₯Ό λ€μ΄: