Current Location Android Kotlin With Latitude Longitude Programmatically

It is necessary to find Current Location Android Kotlin latitude longitude programmatically when you are developing location-based applications.

For example, when finding restaurants near by you, you need your current location, latitude and longitude.

In Current Location Android Kotlin example tutorial, you will learn to get current latitude and longitude of Android device.

We will use Google’s FusedLocationAPI for getting current location latitude longitude.

Following is the output of Current Location Android Kotlin example tutorial programmatically:

Download Source Code For Current Location Android Kotlin Example

[sociallocker]Download Kotlin_Current_GPS_Location[/sociallocker]

Step 1. New Project

Create a new project in Android Studio. Select your first activity as empty activity.

Step 2. Updating build.gradle(Module:app)

In build.gradle(Module:app) file add this:

Above lines will add necessary classes for integrating various google services like GPS, push notification, google map etc.

Step 3. Interfaces

 Implement required interfaces

Step 4. Required instances

Declare instances:

Step 5. Updating onCreate()

Put following in onCreate() function:

Step 6. Overriding methods

Override necessary methods.

Step 7. Adding permissions

Last but not least, put required permissions in AndroidManifest.xml:

If you are targeting marshmallow and after versions (targetSdkVersion >=23) then you have to check for run-time permissions.

You can learn about this topic here at our separate example.

Now full source code:



Step 7.  Full Source code for MainActivity.



In above class, there is a method

This method is used to check whether location service is on or off in your phone. If off, then it will pop up one dialog, which will take the user to settings to enable location service.

After following all the steps, you should be able get current location in terms of latitude and longitude with kotlin source code.

Java Version

Java Version of this tutorial is present at : Current GPS Location Android

Other dreamy tutorials

Cheers and keep healthy coding!

Hardik Parsania

I am mobile app developer. I am always passionate about solving complex and real world problems.I have developed many apps with great interest and superior logical skills.

You may also like...

Leave a Reply

Your email address will not be published. Required fields are marked *