{"id":26154161,"url":"https://github.com/patloew/colocation","last_synced_at":"2025-04-14T07:11:15.145Z","repository":{"id":44907079,"uuid":"291019015","full_name":"patloew/CoLocation","owner":"patloew","description":"🗺 Coroutines Location APIs Library for Android and Kotlin","archived":false,"fork":false,"pushed_at":"2023-02-09T23:33:39.000Z","size":142,"stargazers_count":121,"open_issues_count":5,"forks_count":16,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-03-27T20:51:12.242Z","etag":null,"topics":["android","android-library","coroutines","coroutines-android","coroutines-flow","kotlin","kotlin-android","location","location-services"],"latest_commit_sha":null,"homepage":"","language":"Kotlin","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"other","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/patloew.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2020-08-28T10:31:48.000Z","updated_at":"2024-11-13T14:00:37.000Z","dependencies_parsed_at":"2022-09-05T18:01:54.307Z","dependency_job_id":null,"html_url":"https://github.com/patloew/CoLocation","commit_stats":null,"previous_names":[],"tags_count":2,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/patloew%2FCoLocation","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/patloew%2FCoLocation/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/patloew%2FCoLocation/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/patloew%2FCoLocation/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/patloew","download_url":"https://codeload.github.com/patloew/CoLocation/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248837287,"owners_count":21169374,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["android","android-library","coroutines","coroutines-android","coroutines-flow","kotlin","kotlin-android","location","location-services"],"created_at":"2025-03-11T08:21:44.778Z","updated_at":"2025-04-14T07:11:15.122Z","avatar_url":"https://github.com/patloew.png","language":"Kotlin","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Coroutines Location API Library for Android\n\n[![Build Status](https://travis-ci.org/patloew/CoLocation.svg?branch=main)](https://travis-ci.org/patloew/CoLocation) [![codecov](https://codecov.io/gh/patloew/CoLocation/branch/main/graph/badge.svg)](https://codecov.io/gh/patloew/CoLocation) [![Maven Central](https://img.shields.io/maven-central/v/com.patloew.colocation/colocation.svg?label=Maven%20Central)](https://search.maven.org/search?q=g:%22com.patloew.colocation%22%20AND%20a:%22colocation%22) [![API](https://img.shields.io/badge/API-14%2B-brightgreen.svg?style=flat)](https://android-arsenal.com/api?level=14)\n\nThis library wraps the Location APIs in Kotlin coroutines and `Flow`.\n\n# Usage\n\nCreate a `CoLocation` or `CoGeocoding` instance, preferably by using a dependency injection framework. `CoLocation` is\nvery similar to the classes provided by the Location APIs. Instead of `LocationServices.getFusedLocationProviderClient(context).lastLocation`\nyou can use `coLocation.getLastLocation()`. Make sure to have the Location permission from Marshmallow on, if they are\nneeded by your API requests.\n\nExample:\n\n```kotlin\nval coLocation = CoLocation.from(context);\nval coGeocoder = CoGeocoder.from(context);\n\nval locationRequest = LocationRequest.create()\n        .setPriority(LocationRequest.PRIORITY_HIGH_ACCURACY)\n        .setInterval(5000)\n\nval locationUpdates: MutableLiveData\u003cLocation\u003e = MutableLiveData()\nval addressUpdates: LiveData\u003cAddress?\u003e = locationUpdates.switchMap { location -\u003e\n        liveData { emit(coGeocoder.getAddressFromLocation(location)) }\n    }\n\nval job = viewModelScope.launch {\n    try {\n        coLocation.getLocationUpdates(locationRequest).collect(mutableLocationUpdates::postValue)\n    } catch (e: CancellationException) {\n        // Location updates cancelled\n    }\n}\n\n// The updates get canceled automatically when viewModelScope is cancelled.\n// If you want to cancel it before that, save the job and cancel it.\njob.cancel()\n```\n\nThe following APIs are wrapped by this library:\n\n* `FusedLocationProviderClient` via `CoLocation`\n* `SettingsClient` via `CoLocation`\n* `Geocoder` via `CoGeocoder`\n\nChecking the location settings is simplified with this library, by providing a `SettingsResult` via\n`coLocation.checkLocationSettings(locationRequest)`:\n\n```kotlin\nval settingsResult = coLocation.checkLocationSettings(locationRequest)\n\nwhen (settingsResult) {\n    SettingsResult.Satisfied -\u003e startLocationUpdates()\n    is SettingsResult.Resolvable -\u003e settingsResult.resolve(activity, REQUEST_SHOW_SETTINGS)\n    else -\u003e { /* Ignore for now, we can't resolve this anyway */ }\n}\n\noverride fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {\n    super.onActivityResult(requestCode, resultCode, data)\n    if (requestCode == REQUEST_SHOW_SETTINGS \u0026\u0026 resultCode == Activity.RESULT_OK) {\n        // Resolution success, location settings are now satisfied\n        startLocationUpdates()\n    }\n}\n```\n\n# Sample\n\nA basic sample app is available in the `sample` project.\n\n# Setup\n\nThe library is available on Maven Central. Add the following to your `build.gradle`:\n\n```groovy\ndependencies {\n    implementation 'com.patloew.colocation:colocation:1.1.1'\n    implementation 'com.google.android.gms:play-services-location:21.0.1'\n}\n```\n\nIf you want to use a newer version of Google Play Services, declare the newer version in your `build.gradle`. This then\noverrides the version declared in the library.\n\nCoLocation only works with Android Gradle Plugin 3.0.0 or higher, since it uses Java 8 language features. Don't forget\nto set the source code compatibility to Java 8:\n\n```groovy\nandroid {\n  compileOptions {\n      sourceCompatibility JavaVersion.VERSION_1_8\n      targetCompatibility JavaVersion.VERSION_1_8\n  }\n  kotlinOptions {\n      jvmTarget = \"1.8\"\n  }\n}\n```\n\n# Testing\n\nWhen unit testing your app's classes, `CoLocation` and `CoGeocoder` behavior can be mocked easily. See\n`MainViewModelTest` in the `sample` project for an example test.\n\n# Donations\n\nIf you like the library and want to support the creator for development/maintenance, you can make a donation in Bitcoin\nto `bc1q5uejfyl2kskhhveg7lx4fcwgv8hz88r92yzjsu`. Thank you!\n\n# License\n\n\tCopyright 2020 Patrick Löwenstein\n\n\tLicensed under the Apache License, Version 2.0 (the \"License\");\n\tyou may not use this file except in compliance with the License.\n\tYou may obtain a copy of the License at\n\n\t    http://www.apache.org/licenses/LICENSE-2.0\n\n\tUnless required by applicable law or agreed to in writing, software\n\tdistributed under the License is distributed on an \"AS IS\" BASIS,\n\tWITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n\tSee the License for the specific language governing permissions and\n\tlimitations under the License.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpatloew%2Fcolocation","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fpatloew%2Fcolocation","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpatloew%2Fcolocation/lists"}