[Flutter] Google API MAP, Geolocator

2024. 1. 14. 19:55dev/flutter

728x90
반응형

Geolocator plugin will apply geo-location information.

you should check and request permission.

you should receive GPS location change information.

you should calculate distance your location to your purpose object.

path : https://pub.dev/packages/geolocator

 

geolocator | Flutter Package

Geolocation plugin for Flutter. This plugin provides a cross-platform (iOS, Android) API for generic location (GPS etc.) functions.

pub.dev

flutter pub add geolocator

 

 

your device possibled location function.

  void checkLocationEnabled() async {
    final isLocationEnabled = await Geolocator.isLocationServiceEnabled();

    print('checkLocationEnabled.. isLocationEnabled:$isLocationEnabled');
  }

 

observe current location.

Make sure at least ACCESS_FINE_LOCATION or ACCESS_COARSE_LOCATION 

    Geolocator.getPositionStream().listen((Position event) {
      print('event:$event')
    },);

 

 

check permissions

    final isPermissionLocationGranted = await Geolocator.checkPermission();
    final requestPermissionLocation = await Geolocator.requestPermission();
    print('checkLocationEnabled.. isPermissionLocationGranted:$isPermissionLocationGranted');
    print('checkLocationEnbaled.. requestPermissionLocation:$requestPermissionLocation');

 

 

 

connect Google API

https://console.cloud.google.com/

 

Google 클라우드 플랫폼

로그인 Google 클라우드 플랫폼으로 이동

accounts.google.com

 

create new project.

 

search 'Google Maps Platform'.

 

 

find title API in left banner.

install Android For SDK

register your app package name and SHA-1.

keytool -list -v -keystore ~/.android/debug.keystore -alias androiddebugkey -storepass android -keypass android

 

if occur error message 

keytool 오류: java.lang.Exception: 키 저장소 파일이 존재하지 않음: ~/.android/debug.keystore
java.lang.Exception: 키 저장소 파일이 존재하지 않음: ~/.android/debug.keystore
        at java.base/sun.security.tools.keytool.Main.doCommands(Main.java:923)
        at java.base/sun.security.tools.keytool.Main.run(Main.java:423)
        at java.base/sun.security.tools.keytool.Main.main(Main.java:416)

https://developer.android.com/studio/publish/app-signing?hl=ko

 

앱 서명  |  Android 스튜디오  |  Android Developers

앱 서명 및 보안과 관련된 중요한 개념을 알아보고, Android 스튜디오를 사용하여 Google Play에 출시하기 위해 앱에 서명하는 방법과 Play 앱 서명을 선택하는 방법을 알아보세요.

developer.android.com

 

 

and check Google Map API key

 

and add package google_maps_flutter

flutter pub add google_maps_flutter

 

 

permission and meta-data setting

path : android/app/src/main/AndroidManifest.xml

<manifest xmlns:android="http://schemas.android.com/apk/res/android">
    <permission android:name="android.permission.INTERNET"/>
    <permission android:name="android.permission.ACCESS_FINE_LOCATION" />
    <permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
    <application
        android:label="chool_check"
        android:name="${applicationName}"
        android:icon="@mipmap/ic_launcher">

        <meta-data
            android:name="com.google.android.geo.API_KEY"
            android:value="[API KEY]" />

 

 

check google map latitude(위도), longitude(경도).

https://www.google.co.kr/maps/?hl=ko

 

Google 지도

Google 지도에서 지역정보를 검색하고 지도를 살펴보거나 운전경로 정보를 검색합니다.

www.google.co.kr

 

 

728x90
반응형

'dev > flutter' 카테고리의 다른 글

[Flutter] PIP, Picture in Picture Mode  (0) 2024.01.15
[Flutter] Timer, custom delay point  (0) 2024.01.15
[Flutter] Video Player  (0) 2024.01.15
[Flutter] Navigator #system  (0) 2024.01.14
[Flutter] Permission  (0) 2024.01.14