{"id":21574634,"url":"https://github.com/jintin/fancylocationprovider","last_synced_at":"2025-04-10T16:13:34.890Z","repository":{"id":55584772,"uuid":"312739343","full_name":"Jintin/FancyLocationProvider","owner":"Jintin","description":"Wrapper of FusedLocationProviderClient for Android to support modern usage like LiveData and Flow","archived":false,"fork":false,"pushed_at":"2023-11-01T07:31:33.000Z","size":173,"stargazers_count":68,"open_issues_count":0,"forks_count":5,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-03-24T14:05:55.595Z","etag":null,"topics":["android","androidlocation","flow","livedata"],"latest_commit_sha":null,"homepage":"","language":"Kotlin","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/Jintin.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":".github/FUNDING.yml","license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null},"funding":{"github":null,"patreon":"Jintin","open_collective":null,"ko_fi":"Jintin","tidelift":null,"community_bridge":null,"liberapay":null,"issuehunt":null,"otechie":null,"custom":null}},"created_at":"2020-11-14T03:42:50.000Z","updated_at":"2025-03-08T23:31:52.000Z","dependencies_parsed_at":"2022-08-15T03:40:36.151Z","dependency_job_id":"f6fdaa46-34af-4308-80d3-8c3a4be48135","html_url":"https://github.com/Jintin/FancyLocationProvider","commit_stats":null,"previous_names":[],"tags_count":4,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Jintin%2FFancyLocationProvider","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Jintin%2FFancyLocationProvider/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Jintin%2FFancyLocationProvider/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Jintin%2FFancyLocationProvider/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Jintin","download_url":"https://codeload.github.com/Jintin/FancyLocationProvider/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248251518,"owners_count":21072691,"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","androidlocation","flow","livedata"],"created_at":"2024-11-24T12:10:36.753Z","updated_at":"2025-04-10T16:13:34.868Z","avatar_url":"https://github.com/Jintin.png","language":"Kotlin","funding_links":["https://patreon.com/Jintin","https://ko-fi.com/Jintin","https://www.buymeacoffee.com/jintin"],"categories":[],"sub_categories":[],"readme":"# FancyLocationProvider\n\n[![CircleCI](https://circleci.com/gh/Jintin/FancyLocationProvider.svg?style=shield)](https://circleci.com/gh/Jintin/FancyLocationProvider)\n[![jitpack](https://jitpack.io/v/Jintin/FancyLocationProvider.svg)](https://jitpack.io/#Jintin/FancyLocationProvider)\n\nWrapper of FusedLocationProviderClient for Android to support modern usage like LiveData or Flow.\n\n## Install\n\nAdd [Jitpack](https://jitpack.io/) repository to your root `build.grable`:\n```groovy\nallprojects {\n  repositories {\n    ...\n    maven { url 'https://jitpack.io' }\n  }\n}\n```\n\nThen add dependency in your module `build.gradle`:\n```groovy\ndependencies {\n  implementation 'com.github.jintin:FancyLocationProvider:2.0.0'\n}\n```\n\n## Usage\n\n### LiveData\nHere is an example of how you can create a `LocationLiveData` in `ViewModel` layer, just provide `Context` and the `LocationRequest` with your own config.\n```kotlin\nclass MainViewModel(application: Application) : AndroidViewModel(application) {\n    private val locationRequest =\n        LocationRequest.create()\n            .setInterval(3000)\n            .setFastestInterval(3000)\n            .setPriority(LocationRequest.PRIORITY_HIGH_ACCURACY)\n\n    val locationLiveData = LocationLiveData(application, locationRequest)\n}\n```\nAnd here is how you observe the update on `View` layer.\n```kotlin\n// check for the location permission first\nlocationLiveData.observe(this) {\n    when (it) {\n        is LocationData.Success -\u003e // get location by \"it.location\"\n        is LocationData.Fail -\u003e // Fail to get location\n    }\n}\n\n```\n\n### Flow\n\n```kotlin\nval locationFlow = LocationFlow(application, locationRequest)\n\n// check for the location permission first\n// should inside coroutine\nlocationFlow.get().collect {\n    when (it) {\n        is LocationData.Success -\u003e // get location by \"it.location\"\n        is LocationData.Fail -\u003e // Fail to get location\n    }\n}\n\n```\n\nYou can go to ./app module for more information.\n\n## Custom Location Provider\nFancyLocationProvider using GMS as the default location provider as it serve the most use case.\nBut you can also used it with any other provider you want like Huawei HMS. Just create the custom provider implement the `ILocationProvider` interface like this:\n```kotlin\nclass LocationProvider(\n    private val context: Context,\n    private val locationRequest: LocationRequest\n) : ILocationProvider {\n\n    private val locationProviderClient by lazy {\n        LocationServices.getFusedLocationProviderClient(context)\n    }\n    private val locationListener by lazy {\n        LocationListener()\n    }\n\n    @RequiresPermission(anyOf = [Manifest.permission.ACCESS_COARSE_LOCATION, Manifest.permission.ACCESS_FINE_LOCATION])\n    override fun requestLocationUpdates(locationObserver: ILocationObserver) {\n        locationListener.locationObserver = locationObserver\n        locationProviderClient.requestLocationUpdates(\n            locationRequest,\n            locationListener,\n            Looper.getMainLooper()\n        )\n    }\n\n    override fun removeLocationUpdates() {\n        locationProviderClient.removeLocationUpdates(locationListener)\n    }\n\n    private class LocationListener : LocationCallback() {\n        var locationObserver: ILocationObserver? = null\n\n        override fun onLocationResult(result: LocationResult?) {\n            result?.lastLocation?.let {\n                locationObserver?.onLocationResult(it)\n            }\n        }\n\n        override fun onLocationAvailability(availability: LocationAvailability?) {\n            if (availability?.isLocationAvailable == false) {\n                locationObserver?.onLocationFailed()\n            }\n        }\n    }\n}\n```\nThen you can create the custom provider and transform it into LiveData or Flow.\n```kotlin\nprivate val locationProvider: ILocationProvider = LocationProvider(context, locationRequest)\n\nval locationFlow: LocationFlow = locationProvider.asFlow()\nval locationLiveData: LocationLiveData = locationProvider.asLiveData()\n```\n\n## Contributing\nBug reports and pull requests are welcome on GitHub at [https://github.com/Jintin/FancyLocationProvider](https://github.com/Jintin/FancyLocationProvider).\n\n## License\nThe package is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).\n\n[![Buy Me A Coffee](https://www.buymeacoffee.com/assets/img/custom_images/orange_img.png)](https://www.buymeacoffee.com/jintin)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjintin%2Ffancylocationprovider","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fjintin%2Ffancylocationprovider","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjintin%2Ffancylocationprovider/lists"}