Android ํ๋ซํผ์์ Geolocator()๋ฅผ ์คํํ ๋. CheckGeolocationPermissionStatus() ํจ์๋ GeolocationStatus๊ฐ ๊ฑฐ๋ถ ๋๊ณ ์ฌ์ฉ์์๊ฒ ๊ถํ์ ์์ฒญํ์ง ์์ต๋๋ค. ๊ทธ๋ฌ๋ IOS์์ ์ฒ์์ผ๋ก ๋์ผํ ํจ์๋ฅผ ํธ์ถํ ๋ GeolocationStatus๋ฅผ ์ ์ ์์ผ๋ฏ๋ก Geolocator()๋ฅผ ํธ์ถํด์ผ ํ๋ค๋ ๊ฒ์ ์๊ณ ์์ต๋๋ค. GetCurrentPosition()์ ์ฌ์ฉํ์ฌ ์ฌ์ฉ์์๊ฒ ๊ถํ์ ์์ฒญํ๊ณ ๊ถํ์ด ๋ถ์ฌ๋ ๊ฒฝ์ฐ ์์น๋ฅผ ๋ฐํํฉ๋๋ค.
์ฒ์์ผ๋ก checkGeolocationPermissionStatus๋ฅผ ํธ์ถํ ๋ Android์์ ์ฌ์ฉ์์๊ฒ ๊ถํ์ ์์ฒญํ ์ ์๋ ๋ฐฉ๋ฒ์ด ์์ต๋๊น?
๋ด ์ฝ๋ ์๋ :
Future<void> getLocation() async {
try {
var serviceEnabled = await Geolocator().isLocationServiceEnabled();
if (serviceEnabled) {
var geolocationStatus =
await Geolocator().checkGeolocationPermissionStatus();
if (geolocationStatus == GeolocationStatus.granted || geolocationStatus == GeolocationStatus.unknown) {
position = await Geolocator().getCurrentPosition(desiredAccuracy: LocationAccuracy.high);
return;
}
}
} catch (e) {
print(e);
}
}
์ด ํ๋ฌ๊ทธ์ธ ๊ด๋ฆฌ์๋ ์ปค๋ฎค๋ํฐ๋ฅผ ์ ์ง ๊ด๋ฆฌํ๊ฑฐ๋ ์ง์ํ๋ ๋ฐ ๋ ๊ด์ฌ์ด ์๋ ๊ฒ ๊ฐ์ต๋๋ค. ๋ง์ ๋ฌธ์ ๋ฅผ ๋ณด์์ง๋ง ์ด์ ๋ํ ์ ํํ ๋๋ ๋ฒ๊ทธ ์์ ์๋ฃจ์ ์ด ์์์ต๋๋ค.
๊ทธ๋, ๋น์ ๋ง์ด ๋ง์! ๋๋ ๋ค๋ฅธ ๋ฌธ์ ๋ ๋ต์ด์๋ ๊ฒ์ ๋ณด์์ต๋๋ค. =/
@azeemgujjar , @CNogueira92 , ๊ทธ๋ ์ง ์์ต๋๋ค. ์ ๋ ์ค์ ๋ก ๋ค์ ์ฃผ์ ๋ฆด๋ฆฌ์ค๋ฅผ ์ํด ์ด์ฌํ ๋ ธ๋ ฅํ๊ณ ์์ง๋ง ๋๋ถ๋ถ์ OSS ํ๋ก์ ํธ๋ก์ ์ฌ๊ฐ ์๊ฐ์ ์ด ์์ ์ ์ํํด์ผ ํฉ๋๋ค. ๋ฌผ๋ก ํ๋ฌ๊ทธ์ธ์ ๋ํ ๊ธฐ์ฌ๋ฅผ ํ์ํฉ๋๋ค.
@CNogueira92 ์ง๋ฌธ์ ๋ตํ๊ธฐ ์ํด Android์ iOS๋ ๊ถํ์ ์ฝ๊ฐ ๋ค๋ฅด๊ฒ ์ฒ๋ฆฌํฉ๋๋ค. ๊ธฐ๋ณธ์ ์ผ๋ก Android๋ ๊ถํ์ "๊ฑฐ๋ถ๋จ"์ผ๋ก ์ทจ๊ธํฉ๋๋ค(์ฌ์ฉ์๊ฐ ๋ช ์์ ์ผ๋ก ๊ฑฐ๋ถํ์ง ์์ ๊ฒฝ์ฐ์๋). iOS์๋ ๊ถํ์ด ์์ง ์์ฒญ๋์ง ์์ ์ํฉ์ ๋ํ ํน์ ์ํ๊ฐ ์์ต๋๋ค("๊ฒฐ์ ๋์ง ์์"์ด๋ผ๊ณ ํจ, "์ ์ ์์"์ผ๋ก ๋ฒ์ญ๋จ).
๋ ํ๋ซํผ ๋ชจ๋ checkGeolocationPermissionStatus
๊ฐ denied
๋๋ unknown
๋ฐํํ ๋ ๊ถํ์ ์์ฒญํ๋ ๊ฒ์ด ์ข์ต๋๋ค. ์ฌ์ฉ์๊ฐ "๊ฑฐ๋ถ๋๊ณ ๋ค์ ๋ฌป์ง ์์" ์ต์
์ ์ ํํ ๊ฒฝ์ฐ Geolocator๋ ์ด๋ฅผ ์ธ์งํ๊ณ ๊ถํ์ ์์ฒญํ์ง ์์ต๋๋ค.
์ค์ ๋ก Geolocator๊ฐ ๋ด๋ถ์ ์ผ๋ก ๊ถํ์ ํ์ธํ๊ธฐ ๋๋ฌธ์ ์๋์ผ๋ก ๊ถํ์ ํ์ธํ ํ์์กฐ์ฐจ ์์ต๋๋ค. ๋ฐ๋ผ์ ๋ค์๊ณผ ๊ฐ์ด ์ฝ๋๋ฅผ ์์ ํ๊ฒ ์ ๋ฐ์ดํธํ ์ ์์ต๋๋ค.
Future<void> getLocation() async {
try {
var serviceEnabled = await Geolocator().isLocationServiceEnabled();
if (serviceEnabled) {
position = await Geolocator().getCurrentPosition(desiredAccuracy: LocationAccuracy.high);
} else {
// TODO: ask the user to enable the location services...
}
} catch (e) {
print(e);
}
}
checkGeolocationPermissionStatus
๋ ์๋์ผ๋ก ๊ถํ์ ํ์ธํ๊ณ ์ฌ์ฉ์์๊ฒ ์กฐ์น๋ฅผ ์ทจํ๋๋ก ์ ํธ๋ฅผ ๋ณด๋ด๋ ๊ฒฝ์ฐ์ ํธ๋ฆฌํ ๋ฐฉ๋ฒ์ผ ๋ฟ์
๋๋ค. ๋ด๊ฐ ์ธ๊ธํ ์ ๋ฆด๋ฆฌ์ค์์๋ ์๋์ผ๋ก ๊ถํ์ ์์ฒญํ ์๋ ์์ต๋๋ค. ์ง๊ธ ๊ทธ๋ ๊ฒ ํ๋ ค๋ฉด ์ง๋ฆฌ ์์น ์ถ์ ๊ธฐ์ ํจ๊ป ์ ๊ณต๋๋ location_permissions
ํ๋ฌ๊ทธ์ธ์ ํธ์ถํด์ผ ํฉ๋๋ค. location_permissions ํ๋ฌ๊ทธ์ธ์ ๋ํ ์์ธํ ์ ๋ณด๋ ์ฌ๊ธฐ ์์ ์ฐพ์ ์