


Then open your adle (module) and add the following dependency. Update the Android Studio SDK Manager: click SDK Tools, expand Support Repository, select Google Repository, and then click OK.Go to Android Studio > Tools > Android > SDK Manager .If you haven’t installed it yet, get it now by using the following instructions. Here we are going to use the Google Play Services API, so first, we need to setup our project with the Google Play services SDK. This sample shows a simple way of getting a device's last known location, which is usually equivalent to the device's current location. Getting current location through this API is a bit tricky to implement, but No worries the below step-by-step guidelines will explain the procedure. Get-Current-location-using-FusedLocationProviderClient-in-Android-Kotlin-Demonstrates use of the Google Play services Location API to retrieve the last known location for a device. Utilises low power by choosing the most efficient way to access the location.Provides high accuracy over other options.

It provides simple and easy to use APIs. To Reproduce Steps to reproduce the behavior: 1- open app 2- request to get current location (Locus.In this article, we are going to see how to get user’s current location using FusedLocationProviderApi. Users take their devices everywhere and are constantly using them on the go, and as developers, we can capitalise on that by providing a more contextual experience based on their current location. Now, let’s explore another exciting approach to get the timestamp using the OffsetDateTime class.Knowing a user’s location in an Android app can be extremely useful. Further, we need to convert it to an Instant type and access the toEpochMilli() method for getting the timestamp value. It’s imperative to note that the LocalDateTime object lacks any information about the zone, so we must associate it with the local time zone. Val currentTimestamp: Long = zonedDateTime.toInstant().toEpochMilli() Val zonedDateTime: = localDateTime.atZone(("Asia/Kolkata")) Moving on, let’s also learn how we can get the current timestamp from an instance of the LocalDateTime class: val localDateTime: = () In this case, we created the zoneId object using the preferred time zone of “ America/New_York” and supplied the zoneId instance to the now() method. We must note that we’re using the system’s default zone to initialize the currentZonedDateTime variable.įurthermore, we could also provide a custom ZoneId value to the now() method: val zoneId: = ("America/New_York") Val currentTimestamp: Long = currentZonedDateTime.toInstant().toEpochMilli() Next, let’s create an instance of the ZonedDateTime class and use the toEpochMilli() method to get the current timestamp: val zoneId: = () We used the now() method to query the current date and time from the system clock and then used the toEpochMilli() method to get the current timestamp. Val currentTimeStamp: Long = currentInstant.toEpochMilli()
