현재 위치 가져오기

gozero·2022년 7월 10일
0
  1. Info.plist 셋팅
    <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>

  1. pubspec.yaml 패키지 셋팅
    geolocator: ^8.2.0

  1. 현재 위치 가져오기 코드
    Future<Position> getCurrentUserLocation() async {
        LocationPermission permission = await Geolocator.requestPermission();
        return Geolocator.getCurrentPosition(desiredAccuracy: LocationAccuracy.high)
            .then((location) {
          log(location.toString());
          return location;
        });
    }


iOS 기준으로만 작성을 하였습니다.

profile
Flutter를 제일 좋아하는 앱 프론트엔드 개발자입니다!

0개의 댓글