Android Pie(API 28) ํธ์ถ์ด ์๋ Android Emulator์์ Geolocator().getCurrentPosition()์ ์คํํ ๋ ํธ์ถ์ด ์ ํ ๋ฐํ๋์ง ์์ต๋๋ค.
API 27 ์์น์์ ๋์ผํ ์ฝ๋๋ฅผ ์คํํ๋ฉด ์ ์์ ์ผ๋ก ๋ฐํ๋ฉ๋๋ค. ์ ์๋ฎฌ๋ ์ดํฐ๋ฅผ ๋ง๋ค๋ ค๊ณ ํ์ง๋ง ์๋ฌด ๊ฒ๋ ๋ณ๊ฒฝ๋์ง ์์์ต๋๋ค.
Android Pie๊ฐ ํฌํจ๋ Android ์๋ฎฌ๋ ์ดํฐ(API 28)
๋ฒ์ : 2.1.0
ํ๋ซํผ:
๋๋, ๋ฌด์จ ์ผ ์์ด? :(
์ฌ๊ธฐ๋ ๋ง์ฐฌ๊ฐ์ง!
@savjolovs ๋๋ฒ๊ทธํ๋ฉด ๋๋ฒ๊ฑฐ๊ฐ Geolocator().getCurrentPosition()์์ ์ค์ง๋ฉ๋๋ค. ๋ฐฉ๋ฒ ์ดํ์ ์ค๋จ์ ์ด ์ ์ค๋์ง ์์ต๋๋ค. ์ด ํ๋์ ํ์ธํ ์ ์์ต๋๊น?
ํ์ฅ ์ปจํธ๋กค์ ์ฌ์ฉํ์ฌ ์ผ๋ถ ์ขํ๋ฅผ ํธ์ํ ๋๊น์ง ๋์ผํ ๋์์
๋๋ค.
๋ ๊ฐ์ ๋ฌผ๋ฆฌ์ ์ฅ์น ์ค ํ๋์ ๋์ผํ ๋์์
๋๋ค. ๋จผ์ Android 5์์ - ์ ์๋ํ๊ณ 6์์ - fakegps ์์น๊ฐ ์ฐ๊ฒฐ๋ ๋๊น์ง ์๋ต์ด ์์ต๋๋ค.
์ฌ๊ธฐ์ +1
์์ธ์ด ๋ฌด์์ธ์ง ์๋ ์ฌ๋์ด ์์ต๋๊น? ์ด ๊ธฐ๋ฅ์ ๋ชจ๋ ๊ฒ์ ๊นจ๊ณ ์์ต๋๋ค. ๋ค๋ฅธ ํ๋ฌ๊ทธ์ธ์ ์๋ํ ์ฌ๋์ด ์์ต๋๊น?
๋ฌธ์ ๊ฐ์๋ ์ฌ๋๋ค์ ์ํด ๋ช ๋ฐฑํ ๊ฒ์ ํ์ธํ๊ณ ์์น๋ฅผ ํ์ ํ๊ณ ์ด๋ํ๋ค๋ GPS ์ ํธ๊ฐ ์์ต๋๊น? ์ ๋ฐ์ดํธ๋๊ธฐ ์ ์ ์๋ก์ด ์์น๋ฅผ ๊ธฐ๋ค๋ฆฌ๊ณ ์๋์ง ๊ถ๊ธํ์ญ๋๊น?
@ibrierley ๋ ์ด๋ ์ฌ๋ถ์ ๊ด๊ณ์์ด GPS ์ ํธ๋ฅผ ์์ ํ ์ ์๋ ๊ฒ์ฒ๋ผ ๋ณด์ด์ง๋ง ๋์์ Google ์ง๋์ ๊ฐ์ ๋ค๋ฅธ ์ฑ์ ํ์ฌ ์์น๋ฅผ ์ฐพ๋ ๋ฐ ๋ฌธ์ ๊ฐ ์์ต๋๋ค. lastKnownPosition์ ์ฝ ์๋ฐฑ ๋ฏธํฐ ๋จ์ด์ง ์์น๋ฅผ ๋ฐํํฉ๋๋ค. Android 5์์๋ ์์น ๊ถํ์ ์์ฒญํ์ง ์์๋ ์ ํ ๋ฌธ์ ๊ฐ ์์ต๋๋ค(๊ทธ๋ฌ๋ ํ์คํ์ง ์์, ๋๋ฒ๊ทธ์์ ์ด๊ฒ์ ๋์ณค์ ์ ์์)
์ฑ์ ๋ซ์๋ค๊ฐ ๋ค์ ์ฌ๋ ๊ฒ์ ์ ์ธํ๊ณ Android oreo์์ ๋์ผํ ๋ฌธ์
Android Wear ์๊ณ๋ฅผ ๋ง์ง์๊ฑฐ๋ฆฌ๋ค๊ฐ GPS์ ๋ง์ ๋ฌธ์ ๊ฐ ์์์ง๋ง ๋๋ถ๋ถ ์๋ํ๋ ๊ฒ ๊ฐ์ต๋๋ค(์ค๋ ์๊ฐ์ด ์ง๋๋ฉด ํ์์์๋ ์ ์์ง๋ง ๊ทธ๊ฑด ๋ค๋ฅธ ๋ฌธ์ ๋ผ๊ณ ์๊ฐํฉ๋๋ค).
๋๋ ๋ง์ ๊ฒ์ ์๋ํ๊ธฐ ๋๋ฌธ์ ์ ํํ ๋ฌด์์ด ์๋ํ๋์ง ํ์คํ์ง ์์ง๋ง ๋๊ตฐ๊ฐ๊ฐ ์ด๊ฒ์ ํ์ธํ๊ณ ๋์์ด๋๋์ง ํ์ธํ ์ ์์ต๋๋ค.
0) ์ฅ์น๊ฐ GPS ์ ํธ๋ฅผ ๋ฐ์ ์ ์๋์ง ํ์ธํ์ฌ ์ธ๋ถ ๋๋ ์๋ฎฌ๋ ์ดํฐ๋ฅผ ํตํด ์์น๋ฅผ ์ ๊ณตํฉ๋๋ค(ํ ์คํธ๋ฅผ ์ํด ๋ค์ด๋ก๋ํ GPX ๊ฒฝ๋ก๋ฅผ ์ฅ์น์ ์ ๊ณต).
1) ํ๋ฉด์ด ์ผ์ ธ ์๋์ง ํ์ธํฉ๋๋ค. GPS๊ฐ ํธ์ถ๋๋ ๊ฒ์ด ๋ฌด์์ด๋ ์ต์ ๋ชจ๋์ธ ๊ฒฝ์ฐ GPS๋ ๊ฒฐ๊ณผ ๋ฐํ์ ์ค์งํ ์ ์์ต๋๋ค. Screen ํจํค์ง์ Screen.keepOn(true)์ ์ฌ์ฉํ์ฌ ํ์ํ ๋ ํ๋ฉด์ ๊ฐ์ ๋ก ์ผญ๋๋ค. ํ๋ฉด์ด ๊บผ์ ธ ์์ผ๋ฉด ํ๋ฉด์ด ๋ค์ ์ผ์ง ๋๊น์ง ์ผ๋ จ์ ์์น๋ฅผ โโ์ ์งํ๊ณ ๋ฒํผ๋งํ๋ ๊ฒ์ฒ๋ผ ๋ณด์ ๋๋ค.
2) ์ด๊ฒ์ AndroidManifest.xml์ ์๋ ๋ด ๊ถํ์ด๋ฉฐ ์๋ํด ๋ณผ ๊ฐ์น๊ฐ ์์ต๋๋ค.
```
ํนํ ๊ฐ์ฅ ๋ง์ง๋ง ๋ฒ์ ์ ์ฃผ๋ชฉํ์ญ์์ค. ํ ๋ฒ์ ์์ ๋์ค์ ๋ณ๊ฒฝ ์ฌํญ์ด ์๊ณ ๋์์ด ๋๋ ๊ฒ ๊ฐ์๊ธฐ ๋๋ฌธ์ ๋๋ค. ๋ฐฐํฐ๋ฆฌ ๋๋ฌธ์ wake_lock์ ์ํ์ง ์์ ์๋ ์์ง๋ง ๋ฌธ์ ๊ฐ ์๋ ๋ถ๋ถ์ ์ ๊ฑฐํ๊ธฐ ์ํด ์ด๊ฒ์ ์๋ํ๋ ๊ฒ์ด ์ ์ฉํ ์ ์์ต๋๋ค.
3) ์คํธ๋ฆผ ์๊ฐ ์ด๊ณผ์ ์ด์ํ ์ ์ด ์์ด์ ๊ฒฐ๊ตญ geolocator.getPositionStream์ผ๋ก ์คํธ๋ฆผ์ ์์ํ์ง๋ง ์ค์ ๋ก ์ฌ์ฉํ์ง ์์์ต๋๋ค. ์คํธ๋ฆผ์ด ์คํ ์ค์ธ ์ํ์์ ํ์ด๋จธ๋ฅผ ๊ธฐ๋ฐ์ผ๋ก getCurrentPosition( desiredAccuracy: LocationAccuracy.high )๋ฅผ ํธ์ถํฉ๋๋ค. ๋ด ์๋ ๋ฌธ์ ๋ ํ๋ฉด์ด ๊บผ์ง๋ ๊ฒ์ด๋ฏ๋ก ์ง๊ธ์ ํ์ํ์ง ์๋ค๊ณ ์๊ฐํ์ง๋ง ๊ด์ฌ์ ๊ฐ์ง๊ณ ์๋ํด ๋ณผ ๊ฐ์น๊ฐ ์์ต๋๋ค.
๋๊ตฐ๊ฐ ์์ ๋ฐฉ๋ฒ์ ์๋ํ์ง๋ง ์๋ํ์ง ์๋ ๊ฒฝ์ฐ ์์น ์ ๋ณด๋ง์ผ๋ก ์ต์ํ์ ํ๋ฌํฐ ์ฑ์ ๋ง๋ค ์ ์์ต๋๋ค. ์ ๊ฒฝ์ฐ์๋ ๋์ผํ๊ฒ ์คํจํ๋์ง ํ์ธํ๊ฒ ์ต๋๋ค. ๊ฐ๋ ๊ฒ๋ณด๋ค ํจ์ฌ ๋ ๊ณ ํต ์ค๋ฝ์ต๋๋ค :/.
๊ทํ์ ์ ๋ณด์ ๋ํด @ibrierley ์๊ฒ ๊ฐ์ฌ๋๋ฆฝ๋๋ค. ๊ฐ๋ฅํ ํ ๋นจ๋ฆฌ ์๋ํ๊ณ ๋ฌธ์ ๋ฅผ ํด๊ฒฐํ ๊ฒฝํ์ ๋ํด ๋ณด๊ณ ํ๊ฒ ์ต๋๋ค.
์ค๋ ๋ฌผ๋ฆฌ์ ์ฅ์น์์ GPS ํ
์คํธ์ ๊ฐ์ ์ถ๊ฐ ๋๊ตฌ๋ฅผ ์ฌ์ฉํ์ฌ ์กฐ์ฌํ์ต๋๋ค.
๊ทธ๋์ ๊ตฌ๊ธ๋งต์ด๋ ๋ค๋ฅธ ์ง๋ ์๋น์ค๋ฅผ ํด๋ GPS ํ
์คํธ(์ฃผ๋ณ์ ๊ตฌ๋ฆ๊ณผ ํฐ ๊ฑด๋ฌผ ๋๋ฌธ์ 0 ์ฐ๊ฒฐ 1 ์ฌ์ฉ ๊ฐ๋ฅ)์์ ํ ๋ฅผ ์ฌ์ฉํ ์ ์์ ๋ ์๋ต์ด ์์ต๋๋ค.
์์์ ๋ ์๋ต์ด ์์ง๋ง ์์น ์ต์
์ ์ ์๋ ๊ฑฐ๋ฆฌ๊ฐ ์์ง๋ง ์ด ๊ฒฝ์ฐ์๋ 100%๊ฐ ์๋๋๋ค. ์ด๊ธฐ ์ขํ๋ฅผ ๊ฐ๊ธฐ ์ํด ์ผ์ข
์ GPS ๋๋ฆฌํํธ๊ฐ ํ์ํฉ๋๋ค.
์ค์ ์์น ๋ฐ์ดํฐ๋ฅผ ์ฌ์ฉํ ์ ์๊ธฐ ์ ์ ํ์ฌ ์์น๊ฐ ํ์ํ ์ฑ์ ์์ํ๊ธฐ ์ํด lastknownlocation์ ์ฌ์ฉํ์ฌ ์ฝ๊ฐ์ ํธ๋ฆญ์ ์ํํ์ต๋๋ค.
GPS ์๋น์ค๊ฐ ์คํธ๋ฆผ์ ํตํด ์์น ๋ฐ์ดํฐ๋ฅผ ์ ๊ณตํ ์ค๋น๊ฐ ๋์์์ ๋ํ๋ด๋ Geolocator์์ ๊ฐ๋ฅํ ์ฝ๋ฐฑ๊ณผ ํจ๊ป isReady์ ๊ฐ์ ์ผ์ข
์ ํ๋๊ทธ๋ฅผ ๊ฐ๋ ๊ฒ์ ์๋ง๋ ํ๋ฅญํ ์๋ฃจ์
์ด ๋ ๊ฒ์
๋๋ค.
: ์ฌ๋์ด ์๋ฅผ ๋ค์ด ์๋ํ์ต๋๋ค https://github.com/Lyokone/flutterlocation , ๋๋์ด : https://github.com/Lyokone/flutterlocation ? ๋ฐ๋ผ์ ์ด ํจํค์ง์ ๊ด๋ จ์ด ์๋ ์ค๋ฅ๋ ์ ์ธํ ์ ์์ต๋๋ค.
๋๋ ๊ทธ๊ฒ์ ์๋ํ๊ณ ์ด๊ฒ์ผ๋ก ๋๋ฌ์ต๋๋ค (๊ทธ๋ ์ง ์๋ค๋ ๋ง์ ์๋๋๋ค.
์๋ํด ๋ณผ ๊ฐ์น๊ฐ ์์ต๋๋ค!). ๊ทธ๋ค ๋ชจ๋๋ '์ผ๋ถ' ๋ฌธ์ ๊ฐ ์๋ค๊ณ ์๊ฐํฉ๋๋ค.
์๋๋ก์ด๋์๋ ๋ถ๋ช
ํ์ง ์์ ๊ฒ๋ค์ด ์๊ธฐ ๋๋ฌธ์
๋๋ค.
์ผ๋ฐ์ ์ผ๋ก ์์น๊ฐ ๋ค์ ์ค ์ด๋ ๊ฒ์๋ ๋ฐํ๋์ง ์์ ๋
ํจํค์ง), ํ๋ฌํฐ ์๋ ๋ฌธ์ ๋๋ฌธ์
๋๋ค(์: GPS๊ฐ
์ ์ ๋ชจ๋ ๋๋ GPS ์ ํธ ์์).
2018๋
11์ 15์ผ ๋ชฉ์์ผ ์คํ 7์ 26๋ถ HerrNiklasRaab [email protected]
์ผ๋ค:
๋๊ตฐ๊ฐ๊ฐ ์๋ฅผ ๋ค์ด ์ด๊ฒ์ ์๋ํ ์ ์ด ์์ต๋๊น?
https://github.com/Lyokone/flutterlocation ๋๋ ์ด๊ฒ:
https://github.com/Lyokone/flutterlocation ? ๋ฐ๋ผ์ ๋ค์๊ณผ ๊ฐ์ ์ค๋ฅ๋ฅผ ์ ์ธํ ์ ์์ต๋๋ค.
์ด ํจํค์ง์ ๊ด๋ จ์ด ์์ต๋๋ค.โ
๋น์ ์ด ์ธ๊ธ๋์๊ธฐ ๋๋ฌธ์ ์ด๊ฒ์ ๋ฐ๋ ๊ฒ์ ๋๋ค.
์ด ์ด๋ฉ์ผ์ ์ง์ ๋ต์ฅํ๊ณ GitHub์์ ํ์ธํ์ธ์.
https://github.com/BaseflowIT/flutter-geolocator/issues/135#issuecomment-439160446 ,
๋๋ ์ค๋ ๋ ์์๊ฑฐ
https://github.com/notifications/unsubscribe-auth/ADuG9WRbZuJYvi5N_2xrrku-Jurk6trIks5uvb_SgaJpZM4YKDSm
.
๋๊ตฌ๋ ์ง ๋ด ๊ฒ์ ์๋?
flutter_background_geolocation
๊ด์ฌ์๋ ํ๋ฉด์์ ์๋ํฉ๋๊น?
2018๋
11์ 15์ผ ๋ชฉ์์ผ ์คํ 8:16 Chris Scott ์๋ฆผ @github.com
์ผ๋ค:
๋๊ตฌ๋ ์ง ๋ด ๊ฒ์ ์๋?
flutter_background_geolocation
https://pub.dartlang.org/packages/flutter_background_geolocation#-readme-tab-โ
๋น์ ์ด ์ธ๊ธ๋์๊ธฐ ๋๋ฌธ์ ์ด๊ฒ์ ๋ฐ๋ ๊ฒ์ ๋๋ค.
์ด ์ด๋ฉ์ผ์ ์ง์ ๋ต์ฅํ๊ณ GitHub์์ ํ์ธํ์ธ์.
https://github.com/BaseflowIT/flutter-geolocator/issues/135#issuecomment-439175841 ,
๋๋ ์ค๋ ๋ ์์๊ฑฐ
https://github.com/notifications/unsubscribe-auth/ADuG9f5uvZK0lDnYecMoFZhJnF0ylz6Pks5uvcuygaJpZM4YKDSm
.
์ฑ์ ์ข
๋ฃ( stopOnTerminate: false
)ํ๊ฑฐ๋ ๊ธฐ๊ธฐ๋ฅผ ์ฌ๋ถํ
( startOnBoot: true
)ํด๋ ์๋ํฉ๋๋ค.
getCurrentPosition
์์ ๋ฐํ๋์ง ์๋ ๋์ผํ ๋ฌธ์ ์ ์ง๋ฉดํ๊ณ ์์ต๋๋ค.
๋ค์ ์ฝ๋๊ฐ ์์ต๋๋ค.
position = await Geolocator()
.getCurrentPosition(desiredAccuracy: LocationAccuracy.best);
setState(() {
_position = position;
});
if (position == null)
Fluttertoast.showToast(
msg: 'Position is null', toastLength: Toast.LENGTH_SHORT);
else
Fluttertoast.showToast(
msg: 'Got Position', toastLength: Toast.LENGTH_SHORT);
๊ถํ์ ๋ค์๊ณผ ๊ฐ์ต๋๋ค.
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.hardware.location.gps" />
<uses-permission android:name="android.hardware.location.network" />
<uses-permission android:name="android.permission.WAKE_LOCK" />
.
ํ๋ก๊ทธ๋จ์ ์คํํ๋ฉด ํ๋ฉด ์๋จ์ ์์น ํ์๊ฐ ๋ํ๋๋ฉฐ ํ๋ก๊ทธ๋จ์ ์ข
๋ฃํ ๋๊น์ง ๊ฐ๋งํ ์์ต๋๋ค.
๋์์ด ํ์ํ์ธ์?
API 23์ ์ฌ์ฉํ๋ฉด getCurrentPosition์ด ์๋ํ์ง ์์ต๋๋ค.
ํ์ฌ ์์น๋ฅผ ์ป๊ธฐ ์ํด ์๋ํ๋ ์ด ํจํค์ง ๋๋ ๋์ฒด ํจํค์ง์ ๋ํ ํด๊ฒฐ ๋ฐฉ๋ฒ์ด ์์ต๋๊น?
์กฐ๊ธ ๊น๋ค๋กญ์ต๋๋ค. ๋จผ์ Google ์ง๋ ์ฑ์ ์คํํ์ฌ ์ง๊ธ ์๋ํ๊ฒ ํ๊ณ ๋ด ์์น๋ฅผ ํญํ ๋ GPS ํ์ฑํ ๊ถํ์ ์์ฒญํ๋๋ก ํ ์ ์์ต๋๋ค. ๊ทธ ํ getCurrentPosition์ ๊ฐ์๊ธฐ ๋งค๋ ฅ์ฒ๋ผ ์๋ํฉ๋๋ค.
์ ๊ฒฝ์ฐ์๋ ์ด๋ค API๋ก๋ ์์น๋ฅผ ๊ฒ์ํ ์ ์์ต๋๋ค. ์ด๊ฒ์ด ๋ฌธ์ ๋ฅผ ํด๊ฒฐํ ์ ์๋์ง ํ์คํ์ง ์์ง๋ง
์ฌ๊ธฐ์์ NOT ์ฐ์ฐ์๋ฅผ ์ ๊ฑฐํ๋ ค๊ณ ์๋ํ๊ณ return
๋ฌธ์ ์ถ๊ฐํ๋๋ฐ ์๋ํ์ต๋๋ค. https://github.com/BaseflowIT/flutter-geolocator/blob/master/android/src/main/java/com/baseflow/flutter/plugin/geolocator/tasks/LocationUpdatesUsingLocationManagerTask.java#L52
// If we are listening to multiple location updates we can go ahead
// and report back the last known location (if we have one).
if(mStopAfterFirstLocationUpdate && mBestLocation != null) {
reportLocationUpdate(mBestLocation);
return;
}
ํ๋ก๋์ ์์ ๋๋ฅผ ์ค๋ง์ํค๋ ๋ค๋ฅธ ํ๋ฌ๊ทธ์ธ์ ์ฌ์ฉํ ํ ์ ๋ง ๋น ๋ฅธ ์์ ์ด ํ์ํ๊ธฐ ๋๋ฌธ์ ์ด๊ฒ์ ์ฐ์ฐํ ๋ฐ๊ฒฌํ์ต๋๋ค. API 23(๋ฌผ๋ฆฌ์ ์ฅ์น), API 24(๋ฌผ๋ฆฌ์ ์ฅ์น) ๋ฐ API 28(๋ฌผ๋ฆฌ์ ์ฅ์น)์์ ํ ์คํธํ์ผ๋ฉฐ ๋ฌธ์ ๊ฐ ์์์ ํ์ธํ ์ ์์ต๋๋ค. API 23์์ Google์ด ์์น ๋ฑ์ ๊ฐ์ ํ๋ ๋ฐ ๋์์ด ๋๋์ง ๋ฌป๋ ์ง๋ฌธ์ "์"๋ผ๊ณ ๋งํ์ต๋๋ค. ์ฝ 20์ด ์ ๋ ํ์ ์์น๋ฅผ ๋ก๋ํ์ต๋๋ค. ๊ณผ๊ฑฐ์๋ ์๋ฎฌ๋ ์ดํฐ๊ฐ ์์น๋ฅผ ๋ฐํํ๋๋ก ํ๋ ๋ฐ ์ค์ ๋ฌธ์ ๊ฐ ์์์ต๋๋ค(๊ธฐ๋ณธ Android ๊ฐ๋ฐ). ๊ทธ๋์ ๊ทธ๋ฅ ์๋ฎฌ๋ ์ดํฐ ๋ฌธ์ ์ผ ์ ์์ต๋๊น?
๋๋ ๊ฐ์ ๋ฌธ์ ๊ฐ ์์ผ๋ฉฐ ์๋ํ๋๋ก ์๊ฐ ์ด๊ณผ๋ฅผ ์ค์ ํ์ต๋๋ค. ์๊ฐ ์ด๊ณผ๊ฐ ๋ฐ์ํ๋ฉด getLastKnownPosition()์ ํธ์ถํฉ๋๋ค.
Geolocator().getCurrentPosition().timeout(Duration(seconds: 10)).then((position) {
//getting position without problems
print(position);
}).catchError((error) {
if (error is TimeoutException) {
Geolocator().getLastKnownPosition().then((position) {
//getting last known position
print(position);
}).catchError((error) {
//handle the exception
});
} else {
//handle the exception
}
});
์คํธ๋ฆผ๊ณผ ๋์ผํ ์์ ์ ์ํํ ์๋ ์์ต๋๋ค.
@NMateu ๊ธฐ์ฌํด ์ฃผ์ ์ ๊ฐ์ฌํฉ๋๋ค. ๋งค์ฐ ๋์์ด ๋์์ต๋๋ค!
์๋ฎฌ๋ ์ดํฐ์์๋ ๊ฐ์ ๋ฌธ์ ๊ฐ ์์์ง๋ง .forceAndroidLocationManager = true;
ํด๊ฒฐ๋์์ต๋๋ค. ์ตํฉ ์์น ๊ด๋ฆฌ์๊ฐ ๋๋๋ก ๋ฐฉํด๊ฐ ๋๋ ๊ฒ ๊ฐ์ต๋๋ค.
์ด๊ฒ์ ๋ํ ์์์ด ์์ต๋๊น?
๋ฌธ์ ๋ฅผ ํด๊ฒฐํ ์ฌ๋์ด ์์ต๋๊น? ์ ๋ง ๋๋ด์ผ ํด์, ์ฌ๋ฌ๋ถ!
๊ฐ์ ๋ฌธ์ , ๊ทธ๊ฒ์ ios ์ฅ์น์์ ์ ์๋ํ์ง๋ง ์์ฆ ์๋๋ก์ด๋์์๋ ์์น๋ฅผ ์ป์ ์ ์์ต๋๋ค.
์, ์ค์ ๋ก placemarkFromAddress
๋ฐฉ๋ฒ์ผ๋ก ์ฃผ์๋ฅผ ์ป์ ์ ์์ต๋๋ค. ๊ทธ๋ฌ๋ ์์น ์์ฒด๊ฐ ๊นจ์ก์ต๋๋ค.
์ฌ๊ธฐ ๊ฐ์ ๋ฌธ์
๋ฌดํจ _getUserLocation() ๋น๋๊ธฐ {
Geolocator geolocator = Geolocator()..forceAndroidLocationManager = true;
GeolocationStatus geolocationStatus = geolocator.checkGeolocationPermissionStatus()๋ฅผ ๊ธฐ๋ค๋ฆฝ๋๋ค.
์์น ์์น = Geolocator() ๋๊ธฐ
.getCurrentPosition(desiredAccuracy: LocationAccuracy.high);
๋ชฉ๋ก
.placemarkFromCoordinates(์์น.์๋, ์์น.๊ฒฝ๋);
์ธ์("-----------------");
์ธ์(placemark[0].์์น);
print(geolocator.toString());
print(geolocationStatus.toString());
setState(() {
_initialPosition = ์๋(์์น.์๋, ์์น.๊ฒฝ๋);
locationController.text = placemark[0].name;
});
}
์๋ชป๋ ์์น๋ฅผ ํ์ํฉ๋๋ค.
I/flutter( 7363): ์๋: 37.421999899999996, ๊ฒฝ๋: -122.08405750000001
I/flutter ( 7363): 'Geolocator' ์ธ์คํด์ค
I/flutter ( 7363): GeolocationStatus.granted
๋ฌดํจ _getUserLocation() ๋น๋๊ธฐ {
Geolocator geolocator = Geolocator()..forceAndroidLocationManager = true;
GeolocationStatus geolocationStatus = geolocator.checkGeolocationPermissionStatus()๋ฅผ ๊ธฐ๋ค๋ฆฝ๋๋ค.
์์น ์์น = Geolocator() ๋๊ธฐ
.getCurrentPosition(desiredAccuracy: LocationAccuracy.high);
์์น ํ์ ํ์ = Geolocator() ๋๊ธฐ
.placemarkFromCoordinates(์์น.์๋, ์์น.๊ฒฝ๋);
์ธ์("-----------------");
์ธ์(placemark[0].์์น);
print(geolocator.toString());
print(geolocationStatus.toString());
setState(() {
_initialPosition = ์๋(์์น.์๋, ์์น.๊ฒฝ๋);locationController.text = placemark[0].name; });
}
์ด ์ค๋ํซ์ด ์๋ ์๋ฎฌ๋ ์ดํฐ์์ ์๋ํฉ๋๋ค.
Geolocator()..forceAndroidLocationManager = true;
์ด ํจํค์ง๋ ๋ชจ๋ ๊ฒ์ ๋งค๋ ฅ์ฒ๋ผ ์๋ํ์ต๋๋ค.
(https://github.com/alfanhui/new_geolocation)
๋ช ๊ฐ์ง Android ๊ธฐ๊ธฐ์์ ๋์ผํ ๋ฌธ์ ์ ์ง๋ฉดํ์ต๋๋ค. ๊ทธ๋ฌ๋ ๋๋ ๊ทธ๊ฒ์ ๋ํ ํด๊ฒฐ์ฑ ์ ์ฐพ์์ต๋๋ค -
Geolocator()..forceAndroidLocationManager = true ๊ฐ์ ์ค์ ํ๊ธฐ๋ง ํ๋ฉด ๋ฉ๋๋ค.
์ต์ข Geolocator geolocator = Geolocator()..forceAndroidLocationManager = true;
๋ฒ์ 6.0.0์์ ํด๊ฒฐ๋จ
์์น ์์น = Geolocator.getCurrentPosition(
์ํ๋ ์ ํ๋: LocationAccuracy.low,forceAndroidLocationManager: true);
๋ด ๋ฌธ์ ๋ฅผ ํด๊ฒฐํ์ต๋๋ค.
forceAndroidLocationManager ์ค์ ๋นจ๊ฐ์ ์ค์ด ํ์๋๊ณ ์ค๋ฅ๋ ....."'forceAndroidLocationManager' ์ค์ ์๊ฐ 'Geolocator' ์ ํ์ ๋ํด ์ ์๋์ง ์์์ต๋๋ค.
'forceAndroidLocationManager'๋ฅผ ์ ์ํ๋ ๋ผ์ด๋ธ๋ฌ๋ฆฌ๋ฅผ ๊ฐ์ ธ์ค๊ฑฐ๋ ๊ธฐ์กด setter์ ์ด๋ฆ์ผ๋ก ์ด๋ฆ์ ์์ ํ๊ฑฐ๋ 'forceAndroidLocationManager'๋ผ๋ ์ด๋ฆ์ setter ๋๋ ํ๋๋ฅผ ์ ์ํด ๋ณด์ญ์์ค."......... ๋๊ตฐ๊ฐ ๋๋ฅผ ๋์์ค ์ ์์ต๋๋ค.
@aditikumar-png ์ด๋ค ๋ฒ์ ์ ์์น ์ ๋ณด๋ฅผ ์ฌ์ฉํ๊ณ ์์ต๋๊น? ์ต๊ทผ์ ๋ฒ์ 6.x๋ก ์
๋ฐ์ดํธํ์ ๊ฒ์
๋๋ค. ์ด ๋ฒ์ ์๋ ์ฃผ์ ๋ณ๊ฒฝ ์ฌํญ์ด ์์ต๋๋ค. Geolocator().forceAndroidLocationManager
์์ฑ์ getCurrentPosition
๋ฐ getPositionStream
๋ฉ์๋์ ๋ช
๋ช
๋ ๋งค๊ฐ๋ณ์๋ก ์ด๋ํ์ต๋๋ค.
์ด๊ฒ์ ์ด์ ๋ค์๊ณผ ๊ฐ์ด ์ง๋ฆฌ ๊ฒ์๊ธฐ๋ฅผ ์ฌ์ฉํ ์ ์์์ ์๋ฏธํฉ๋๋ค.
final position = await Geolocator.getCurrentPosition(forceAndroidLocationManager: true);
์ด์ ๋์ :
final geolocator = Geolocator();
geolocator.forceAndroidLocationManager = true;
final position = await geolocator.getCurrentPosition();
@aditikumar-png ์ด๋ค ๋ฒ์ ์ ์์น ์ ๋ณด๋ฅผ ์ฌ์ฉํ๊ณ ์์ต๋๊น? ์ต๊ทผ์ ๋ฒ์ 6.x๋ก ์ ๋ฐ์ดํธํ์ ๊ฒ์ ๋๋ค. ์ด ๋ฒ์ ์๋ ์ฃผ์ ๋ณ๊ฒฝ ์ฌํญ์ด ์์ต๋๋ค.
Geolocator().forceAndroidLocationManager
์์ฑ์getCurrentPosition
๋ฐgetPositionStream
๋ฉ์๋์ ๋ช ๋ช ๋ ๋งค๊ฐ๋ณ์๋ก ์ด๋ํ์ต๋๋ค.์ด๊ฒ์ ์ด์ ๋ค์๊ณผ ๊ฐ์ด ์ง๋ฆฌ ๊ฒ์๊ธฐ๋ฅผ ์ฌ์ฉํ ์ ์์์ ์๋ฏธํฉ๋๋ค.
final position = await Geolocator.getCurrentPosition(forceAndroidLocationManager: true);
์ด์ ๋์ :
final geolocator = Geolocator(); geolocator.forceAndroidLocationManager = true; final position = await geolocator.getCurrentPosition();
์ ๋ง ๊ณ ๋ง์ต๋๋ค!!!!! u๋ ๋ช ์ด ๋ง์ ๋ด ๋ฌธ์ ๋ฅผ ํด๊ฒฐํ์ต๋๋ค. ๋๋ 9์๊ฐ ์ดํ๋ก ์ด๊ฒ์ผ๋ก ๊ณ ์ํ์ต๋๋ค
๊ฐ์ฅ ์ ์ฉํ ๋๊ธ
๋๋ ๊ฐ์ ๋ฌธ์ ๊ฐ ์์ผ๋ฉฐ ์๋ํ๋๋ก ์๊ฐ ์ด๊ณผ๋ฅผ ์ค์ ํ์ต๋๋ค. ์๊ฐ ์ด๊ณผ๊ฐ ๋ฐ์ํ๋ฉด getLastKnownPosition()์ ํธ์ถํฉ๋๋ค.
์คํธ๋ฆผ๊ณผ ๋์ผํ ์์ ์ ์ํํ ์๋ ์์ต๋๋ค.