-
Notifications
You must be signed in to change notification settings - Fork 4
π»πππππππ ππππππππ π§
Devrath edited this page Dec 29, 2022
·
1 revision
**Contents** |
---|
Setup |
About permissions used in the app for location tracking |
Getting current users location |
Locate the current user |
Service to track the users moment in background |
π° Steps for creating a debug key for map-API
* Get the package name from your manifest
* Get the SHA-1 certificate fingerprint from your application(You can use GradleTasks -> android -> siginingReport)
* There is a useful link to generate the SHA-1 key(https://stackoverflow.com/a/68728675/1083093)
* Place the SHA Keys: https://console.cloud.google.com/google/maps-apis/credentials?project=distance-tracker-369716
* Enable google maps SDK for Android and get the key, Useful link(https://developers.google.com/maps/documentation/android/start#get-key)
* Then add a string resource(SECRET.xml) in project location SRC -> DEBUG -> RES -> VALUES -> SECRET.XML and the key
* <resources><string name="google_maps_key" templateMergeStrategy="preserve" translatable="false">dddsdjbeioudhqweuhd8</string></resources>
π° Steps for creating a release key for map-API
* Generate a keystore file by entering the proper credentials
* Use the keystore file to generate the SHA-1 key
* COMMANDβ keytool -list -v -keystore /Users/devrath/keys/Keystore -alias AliasName
* Useful link:β How to get API key: https://developers.google.com/maps/documentation/android/start#get-key
* Place the SHA Keys: https://console.cloud.google.com/google/maps-apis/credentials?project=distance-tracker-369716
* Then add a string resource(SECRET.xml) in project location SRC -> RELEASE -> RES -> VALUES -> SECRET.XML and the key
* <resources><string name="google_maps_key" templateMergeStrategy="preserve" translatable="false">SHJJS8s8shhdsdssdss</string></resources>
π° Create firebase account
* Since the project uses firebase to register crashes we need to create a firebase account.
* Place the google-services.json in the project app level.
π°ππππ πππππππππππ ππππ πππ πππ πππ πππ ππππππππ ππππππππ
π
βͺοΈ In android sharing user location is very delicate so a series of permissions need to be provided from user
βͺοΈ There are two scenarios to handle when it comes to runtime permissions ACCESS_FINE_LOCATION
, ACCESS_BACKGROUND_LOCATION
<!--
DESCRIPTION: -> The permission ACCESS_FINE_LOCATION is needed to get the user's location from the device
RUNTIME-PERMISSION: -> Needed
-->
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<!--
DESCRIPTION: -> The permission ACCESS_BACKGROUND_LOCATION is needed from android-10 and above in older version its by default provided
RUNTIME-PERMISSION: -> Needed
-->
<uses-permission android:name="android.permission.ACCESS_BACKGROUND_LOCATION" />
<!--
DESCRIPTION: -> The permission FOREGROUND_SERVICE is needed to display the foreground notification as a service
RUNTIME-PERMISSION: -> Not needed
-->
<uses-permission android:name="android.permission.FOREGROUND_SERVICE" />
Runtime Permission |
Background tracking permission |
---|---|
πΆππππππ πππππππ ππππ ππππππππ
π
- We use fused-location-provider to get the current location of the user
- In earlier API's it was very complex to get user's current location. With the fused location provider encapsulates all the logic and provides the current location from the user
- In our app we request the last known position of the user in certain intervals of time and get the specific
lat/lng
for that location. - So, the entire journey we get a list of
lat/lng
and we draw apolyline
for complete list creating apath
- Once the map is loaded, We can access the Location button on the map and by simulating a click action on the map, we and redirect the camera to the user location.
Locating user |
---|
πππππππ ππ πππππ πππππ ππππππ ππ ππππππππππ
βοΈ
- When we require tracking the user journey we need to use the fused location service continously at certain intervals of time and get the
lat/lng
position of the user - This tracking needs to happen continously regards of application is in foreground or background. In this scenario we need to use a foreground service to run the location mechanish continously which also require a notification to be shown on the app tray which displays distance travelled.
- When new location update is available, we need to add that location to the list of locations maintained as live data in the service.
- We observe the live data from the fragment and update the map
polyline
andcamera position
accordingly.