play services location - boostcampwm-2024/and04-Nature-Album GitHub Wiki

Google-Service-Location

๋Œ€๋ถ€๋ถ„์˜ ๊ฒฝ์šฐ ์‚ฌ์šฉ์ž์˜ ํ˜„์žฌ ์œ„์น˜์— ๊ด€์‹ฌ์ด ์žˆ์œผ๋ฉฐ ์‚ฌ์šฉ์ž์˜ ํ˜„์žฌ ์œ„์น˜๋Š” ์ผ๋ฐ˜์ ์œผ๋กœ ๋งˆ์ง€๋ง‰์œผ๋กœ ์•Œ๋ ค์ง„ ๊ธฐ๊ธฐ์˜ ์œ„์น˜์™€ ๊ฐ™์Šต๋‹ˆ๋‹ค

Android Developers ๋งˆ์ง€๋ง‰์œผ๋กœ ์•Œ๋ ค์ง„ ์œ„์น˜ ๊ฐ€์ ธ์˜ค๊ธฐ | Sensors and location

ํ†ตํ•ฉ ์œ„์น˜ ์ •๋ณด ์ œ๊ณต์ž๋Š” Google Play ์„œ๋น„์Šค์˜ Location API ์ค‘ ํ•˜๋‚˜์ž…๋‹ˆ๋‹ค. ๊ธฐ๋ณธ ์œ„์น˜ ๊ธฐ์ˆ ์„ ๊ด€๋ฆฌํ•˜๊ณ  ๋‹จ์ˆœํ•œ API๋ฅผ ์ œ๊ณตํ•˜๋ฏ€๋กœ, ๋†’์€ ์ˆ˜์ค€์œผ๋กœ ์š”๊ตฌ์‚ฌํ•ญ(๋†’์€ ์ •ํ™•์„ฑ์ด๋‚˜ ์ €์ „๋ ฅ ๋“ฑ)์„ ์ง€์ •ํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค. ์ด API๋Š” ๊ธฐ๊ธฐ์˜ ๋ฐฐํ„ฐ๋ฆฌ ์ „๋ ฅ ์‚ฌ์šฉ์„ ์ตœ์ ํ™”ํ•ด ์ค๋‹ˆ๋‹ค.

Google for Developers FusedLocationProviderCliend | Google play services

์ตœ์ ์˜ ์œ„์น˜ ์„ ํƒ

private val client by lazy { LocationServices.getSettingsClient(context) }

The main entry point for interacting with the location settings-enabler APIs.

To use this API, first create a LocationSettingsRequest.Builder and add all of the LocationRequests that the app will be using:

private val builder by lazy {
        LocationSettingsRequest.Builder().addLocationRequest(
            LocationRequest.Builder(
                Priority.PRIORITY_BALANCED_POWER_ACCURACY,
                Long.MAX_VALUE,
            ).build()
        )
    }

LocationRequest.Builder(int priority, long intervalMillis)

  • priority : Google for Developers Priority | Google Play services : ์ •ํ™•๋„์™€ ์ „๋ ฅ ์‚ฌ์šฉ ๊ธฐ์ค€
    • *PRIORITY_BALANCED_POWER_ACCURACY : ์œ„์น˜ ์ •ํ™•๋„์™€ ์ „๋ ฅ ์‚ฌ์šฉ๊ฐ„์˜ ๊ท ํ˜• ์œ ์ง€*
  • intervalMillis : ์œ„์น˜ ์—…๋ฐ์ดํŠธ ์š”์ฒญ ๊ฐ„๊ฒฉ
    • Long.MAX_VALUE : ์šฐ๋ฆฌ๋Š” ๋‹จ์ง€ GPS ์ƒํƒœ๊ฒ€์‚ฌ๋ฅผ ์œ„ํ•ด LocationRequest ๊ฐ€ ํ•„์š”ํ•˜๊ธฐ ๋•Œ๋ฌธ์— intervalMillis๊ฐ€ ํ•„์š”์—†๋‹ค. โ†’ ์ตœ๋Œ€๋กœ
private fun resolveLocationSettings(
        resolvable: ResolvableApiException,
        showGPSActivationDialog: (IntentSenderRequest) -> Unit,
    ) {
        val intentSenderRequest = IntentSenderRequest.Builder(resolvable.resolution).build()
        try {
            showGPSActivationDialog(intentSenderRequest)
        } catch (e: IntentSender.SendIntentException) {
            e.printStackTrace()
        }
    }

ResolvableApiException

  • Google for Developers ResolvableApiException

  • ์•ฑ์˜ ์š”์ฒญ๊ณผ ์‹œ์Šคํ…œ ์„ค์ •์ด ์ถฉ๋Œํ•  ๋•Œ ๋ฐœ์ƒํ•˜๋Š” ์˜ˆ์™ธ

  • ResolvableApiException.resolution: PendingIntent

    • ์‹คํŒจ๋ฅผ ํ•ด๊ฒฐํ•˜๊ธฐ ์œ„ํ•œ PendingIntent (๋‚˜์ค‘์— ์‹คํ–‰๋  Intent๋ฅผ ์˜ˆ์•ฝํ•ด๋‘๋Š” ๊ฐ์ฒด)
  • ์ด ๊ฐ์ฒด๋ฅผ ํ†ตํ•ด IntentSenderRequest๋ฅผ ์–ป์„ ์ˆ˜ ์žˆ๋‹ค.

IntentSenderRequest.Builder(@NonNull PendingIntent pendingIntent)

  • PendingIntent ๊ฐ์ฒด๋ฅผ ์ž…๋ ฅ์œผ๋กœ ๋ฐ›์•„ ํ•ด๋‹น PendingIntent์— ๋‚ด์žฅ๋œ IntentSender๋ฅผ ์ถ”์ถœํ•˜์—ฌ ์‚ฌ์šฉ
GPT ์š”์•ฝ

IntentSender๋ž€?

  • ๋‚ด๊ฐ€ ์„ค์ •ํ•œ ์ž‘์—…(์˜ˆ: ์•Œ๋ฆผ์„ ๋ณด๋‚ด๊ธฐ, ์„ค์ • ํ™”๋ฉด ์—ด๊ธฐ ๋“ฑ)์„ ๋‹ค๋ฅธ ์•ฑ์ด ๋Œ€์‹  ์ˆ˜ํ–‰ํ•  ์ˆ˜ ์žˆ๋„๋ก ์š”์ฒญ์„œ๋ฅผ ๋งŒ๋“ค์–ด์ฃผ๋Š” ์—ญํ• ์ž…๋‹ˆ๋‹ค.

์–ด๋–ป๊ฒŒ ์ž‘๋™ํ•˜๋‚˜์š”?

  • IntentSender๋Š” ๋ฏธ๋ฆฌ ์ค€๋น„ํ•ด๋‘” Intent๋ฅผ ํŠน์ • ์‹œ์ ์— ์ˆ˜ํ–‰ํ•˜๋„๋ก ํ•˜๋Š” ๋ฐฉ๋ฒ•์ž…๋‹ˆ๋‹ค.

์˜ˆ์‹œ: ์•Œ๋ฆผ์„ ํด๋ฆญํ•˜๋ฉด ํŠน์ • ํ™”๋ฉด์„ ์—ด๋„๋ก ๋ฏธ๋ฆฌ ์„ค์ •ํ•ด๋‘๋Š” ๊ฒƒ์ด ๊ฐ€๋Šฅํ•ฉ๋‹ˆ๋‹ค. ์•Œ๋ฆผ์„ ํด๋ฆญํ•˜๋Š” ์‹œ์ ์—, ๋ฏธ๋ฆฌ ์„ค์ •๋œ IntentSender๊ฐ€ ์‹คํ–‰๋ฉ๋‹ˆ๋‹ค.

์™œ ์กฐ์‹ฌํ•ด์•ผ ํ•˜๋‚˜์š”?

  • ๋‹ค๋ฅธ ์•ฑ์— IntentSender๋ฅผ ๋„˜๊ธฐ๋ฉด, ๋‹ค๋ฅธ ์•ฑ์ด ๋งˆ์น˜ ๋‚˜์ธ ๊ฒƒ์ฒ˜๋Ÿผ ๋‚ด ์ž‘์—…์„ ์ˆ˜ํ–‰ํ•  ์ˆ˜ ์žˆ๋Š” ๊ถŒํ•œ์„ ๊ฐ–๊ฒŒ ๋ฉ๋‹ˆ๋‹ค.

  • ๊ทธ๋ž˜์„œ ๋ณดํ†ต IntentSender๋Š” ๋‚ด ์•ฑ์˜ ํŠน์ • ์ปดํฌ๋„ŒํŠธ(์˜ˆ: ๋‚ด ํ™”๋ฉด์ด๋‚˜ ์„œ๋น„์Šค)๋กœ๋งŒ ์—ฐ๊ฒฐ๋˜๋„๋ก ์„ค์ •ํ•˜๋Š” ๊ฒƒ์ด ์•ˆ์ „ํ•ฉ๋‹ˆ๋‹ค.

IntentSender์™€ PendingIntent์˜ ๊ด€๊ณ„

  • IntentSender๋Š” PendingIntent์—์„œ ๋งŒ๋“ค์–ด์ง‘๋‹ˆ๋‹ค. ์ฆ‰, PendingIntent.getIntentSender()๋ฅผ ํ˜ธ์ถœํ•ด IntentSender๋ฅผ ๊ฐ€์ ธ์˜ฌ ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.
  • ๋ฐ˜ํ™˜ ํƒ€์ž… : IntentSenderRequest
    • ์ด ํƒ€์ž…์€ registerForActivityResult ์— ์‚ฌ์šฉ๋จ
โš ๏ธ **GitHub.com Fallback** โš ๏ธ