{"id":22360310,"url":"https://github.com/balwindersingh1989/androidbestlocationtracker","last_synced_at":"2025-07-30T13:31:43.410Z","repository":{"id":41546337,"uuid":"149750519","full_name":"balwinderSingh1989/androidBestLocationTracker","owner":"balwinderSingh1989","description":"Android Library to get best available location .  Getting location in background or foreground is just a 5 lines of code away :) ","archived":false,"fork":false,"pushed_at":"2022-12-27T14:14:28.000Z","size":225,"stargazers_count":39,"open_issues_count":0,"forks_count":10,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-06-30T05:37:42.408Z","etag":null,"topics":["android","android-app","android-development","android-library","android-location","android-location-navigator","android-sdk","androidlocation","location","permissions"],"latest_commit_sha":null,"homepage":"","language":"Kotlin","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/balwinderSingh1989.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2018-09-21T10:49:11.000Z","updated_at":"2025-06-16T09:32:00.000Z","dependencies_parsed_at":"2023-01-31T03:32:23.075Z","dependency_job_id":null,"html_url":"https://github.com/balwinderSingh1989/androidBestLocationTracker","commit_stats":null,"previous_names":[],"tags_count":15,"template":false,"template_full_name":null,"purl":"pkg:github/balwinderSingh1989/androidBestLocationTracker","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/balwinderSingh1989%2FandroidBestLocationTracker","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/balwinderSingh1989%2FandroidBestLocationTracker/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/balwinderSingh1989%2FandroidBestLocationTracker/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/balwinderSingh1989%2FandroidBestLocationTracker/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/balwinderSingh1989","download_url":"https://codeload.github.com/balwinderSingh1989/androidBestLocationTracker/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/balwinderSingh1989%2FandroidBestLocationTracker/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":267875484,"owners_count":24158780,"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","status":"online","status_checked_at":"2025-07-30T02:00:09.044Z","response_time":70,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"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-app","android-development","android-library","android-location","android-location-navigator","android-sdk","androidlocation","location","permissions"],"created_at":"2024-12-04T16:15:29.174Z","updated_at":"2025-07-30T13:31:43.074Z","avatar_url":"https://github.com/balwinderSingh1989.png","language":"Kotlin","funding_links":[],"categories":[],"sub_categories":[],"readme":"# androidBestLocationTracker\nGet best available locaiton from android locaiton providers \n\nuse latest version 2.0.10\n\n\nWhats comming next ? \n\nTo make location data as stream and not callback. Will be incorporating flow{} to this lib.\n\n\u003ckbd\u003e\n\u003cimg src=\"https://3c1703fe8d.site.internapcdn.net/newman/gfx/news/hires/2018/location.jpg\" alt=\"Live Location Sharing\" width=\"300\"\u003e\n\u003c/kbd\u003e\n\u003c/p\u003e\n========================\n\nAndroid Best Location Tracker is an Android library that helps you get user best  location with a object named `BaseLocationStrategy`\nthat would give a accurate location using accuracy alogirthm.  \n\n\n\n### Installation\n\nAdd this to your `build.gradle` file\n\n```gradle\nrepositories {\n    maven {\n        url \"https://jitpack.io\"\n    }\n}\n\ndependencies {\n         implementation 'com.github.balwinderSingh1989:androidBestLocationTracker:2.0.6'\n}\n```\n\nDon't forget to add the following permissions to your *AndroidManifest.xml*\n\n```xml\n\u003cuses-permission android:name=\"android.permission.INTERNET\" /\u003e\n\u003cuses-permission android:name=\"android.permission.ACCESS_FINE_LOCATION\" /\u003e\n\u003cuses-permission android:name=\"android.permission.ACCESS_COARSE_LOCATION\" /\u003e\nadd below if you need locaton in background for android Q and above. Check out this blog\nhttps://www.ackee.agency/blog/how-to-fetch-location-in-background-on-android\n\u003cuses-permission android:name=\"android.permission.ACCESS_BACKGROUND_LOCATION\" /\u003e\n```\n\n\n### Use\n\n\nTo create a tracker you just need to add the below code in your Android Activity/Service\n\n```java\n// You can pass an ui Context but it is not mandatory getApplicationContext() would also works\n// Be aware if you target android 23, you'll need to handle the runtime-permissions !\n// see http://developer.android.com/reference/android/support/v4/content/ContextCompat.html\nif (    ContextCompat.checkSelfPermission(ctx, Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED\n    || ContextCompat.checkSelfPermission(ctx, Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED) {\n        // You need to ask the user to enable the permissions\n} else {\n    setupLocation();\n}\n\n\n  private void setupLocation()\n    {\n         baseLocationStrategy = getLocationStatergy(this, this)\n\n         baseLocationStrategy?.apply {\n                  setDisplacement(5)\n                  setPeriodicalUpdateTime(1000)\n                  setPeriodicalUpdateEnabled(true)\n\n                  shouldFetchWhenInBackground(fetchAggresively = true, lifecycle)\n\n                  /**\n                  NOTE :SET  fetchAggresively true if you need location in background faster than android default (which is few times in a hour).\n                  when this is TRUE : for android API  \u003c 31, location will be fetched by foreground service and for above lib will use workmanger\n\n\n                  REMEMBER : You would need permission \u003cuses-permission android:name=\"android.permission.ACCESS_BACKGROUND_LOCATION\" /\u003e to fecth location in\n                  background for Adnroid 10 and above\n\n\n\n                  lifecycle  = set this to activity as lib would use this lifecycle to bind the foreground service and would start the service once the activity is not visible\n                  (i.e activity is in background)\n\n                  **/\n\n                  startListeningForLocationChanges(object : LocationChangesListener {\n                      override fun onBetterLocationAvailable(location: Location?) {\n                          Log.d(TAG, \"onBetterLocationAvailable  ${location.toString()}\")\n                      }\n\n                      override fun onConnected() {\n                          Log.d(TAG, \"onConnected\")\n                      }\n\n                      override fun onConnectionStatusChanged() {}\n                      override fun onFailure(s: Error) {\n                         //check error codes here\n\n                      }\n                  })\n                  baseLocationStrategy?.startLocationUpdates()\n  }\n\n\n\n//also from android 10 and above , one cannot ask foreground and background location at the same time. Hence for background location one should have a proper use case\n//and UI option to trigger background location. Once you have decided the use case, you can call below fun to let lib known that ACCESS_BACKGROUND_LOCATION is granted, so that\n//lib can start providing you location when your app is in background.\n\n     btnStartBackgroundFetch.setOnClickListener {\n            if (ContextCompat.checkSelfPermission(\n                    this,\n                    Manifest.permission.ACCESS_BACKGROUND_LOCATION\n                ) == PackageManager.PERMISSION_GRANTED\n\n            ) {\n                baseLocationStrategy?.backgroundLocationPermissionGranted()\n            } else {\n                this.requestPermissions(\n                    arrayOf(\n                        Manifest.permission.ACCESS_BACKGROUND_LOCATION,\n                    ), REQUEST_CODE\n                )\n            }\n        }\n\n\n\n\n```\n\nAnd it's done, as soon as a location gets available, it will call the `onLocationChanged()` with latest and best available locaition.\nAlso, to get lastKnown location any time (this should only we called if )\n\n```java\nbaseLocationStrategy.getLastLocation();\n```\n\n### Manage the tracker\n\nBy default, after a `baseLocationStrategy` is created, it automatically starts listening to updates... and never stops.\n`LocationTracker` has two methods to *start* and *stop* listening for updates.\n\nIf you want to *stop* listening for updates, just call the `  baseLocationStrategy.stopListeningForLocationChanges()` method.\nFor example, if you need a *one shot* position, you can do that:\n\n```java\n baseLocationStrategy.startListeningForLocationChanges(new LocationChangesListener() {\n            @Override\n            public void onLocationChanged(Location location) {\n                //get best accurate location here and here you can stop\n                baseLocationStrategy.stopListeningForLocationChanges()\n            }\n            @Override\n            public void onConnected() {\n                //best location provider has been connected and you will surely get location changes now\n            }\n            @Override\n            public void onConnectionStatusChanged() {\n            }\n            @Override\n            public void onFailure(String s) {\n            }\n        });\n        baseLocationStrategy.startLocationUpdates();\n```\n\nYou can also do it in the `onPause()` Activity method if you want.\n\n```java\n@Override\nprotected void onPause() {\n\tif(baseLocationStrategy != null) {\n\t\tbaseLocationStrategy.stopListeningForLocationChanges();\n\t}\n\tsuper.onPause();\n}\n```\n\nREMEMBER! A `LocationTracker` never stops untill you tell it to do so.\n\nYou may want to start listening for updates after all. To do that, `LocationTracker` has a public method named `startLocationUpdates()`, call it when you want.\n\nFor example, in the `onResume()` Activity method:\n```java\n@Override\nprotected void onResume() {\n\tif(baseLocationStrategy != null) {\n\t\tbaseLocationStrategy.startLocationUpdates();\n\t}\n\tsuper.onResume();\n}\n```\n\n### Contact \u0026 Questions\n\nIf you have any questions, fell free to send me an email at er.vicky1989@gmail.com\nYou can also fork this project, or open an issue :)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbalwindersingh1989%2Fandroidbestlocationtracker","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fbalwindersingh1989%2Fandroidbestlocationtracker","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbalwindersingh1989%2Fandroidbestlocationtracker/lists"}