How to Obtain Current Location Using Android Location Manager [Part: 1]


Integrating location feature in your app adds great potential in making your app seem smart to end-users.

And with your end-users location data, you can predict their potential actions, regular places they visit and much more.

This basically helps in a way to understanding your users.

So if you’re developing an app that includes location-based features, then why not make it smarter by automatically finding user’s current location with Android location manager?

This class basically provides access to Google location services. And these services allows Android app to obtain the latest/current device’s location.

In the first part of this tutorial series, we’ll show how to integrate Google maps in your Android location. Then in the next part, we’ll show how to automate the process of obtaining the current location of user’s device.

Let’s Get Started

First of all, you need to make settings in the developer console.

Go to and create a new project.

After creating a new project, create Key by going to Credential-> Create credentials-> APIKEY.



Now you can add restrictions if you needed.

Note: If you want to make it project independent, then no need to add package name and SHA1 key.

Now enable Google Map Android API Service (If not enabled)

Go to Dashboard -> Enable API -> Google Map Android API.

Once you’ve done all the settings in the developer console, open your Android Studio to develop the demo.

Firstly, create a new project.

Now to automatically add the map in the new activity, right click on the package -> New -> Google map activity.


Next, Setup your key through main -> res -> googlemapapi.xml


After setting up the above key, go to Android manifest file and add the shown metadata if not added.


Also, don’t forget to give the necessary permissions.

Next, open Gradle and check whether the following dependency is added or not in build.gradle of project’s main module.

Start Code Integration

      public class MapsActivity extends FragmentActivity implements OnMapReadyCallback {
      private GoogleMap mMap;
      protected void onCreate(Bundle savedInstanceState) {
      // Obtain the SupportMapFragment and get notified when the map is ready to be used.
      SupportMapFragment mapFragment = (SupportMapFragment) getSupportFragmentManager()
      * Manipulates the map once available.
      * This callback is triggered when the map is ready to be used.
      * This is where we can add markers or lines, add listeners or move the camera. In this case,
      * we just add a marker near Sydney, Australia.
      * If Google Play services is not installed on the device, the user will be prompted to install
      * it inside the SupportMapFragment. This method will only be triggered once the user has
      * installed Google Play services and returned to the app.
      public void onMapReady(GoogleMap googleMap) {
      mMap = googleMap;
      // Add a marker in Sydney and move the camera
      LatLng sydney = new LatLng(-34, 151);
      mMap.addMarker(new MarkerOptions().position(sydney).title("Marker in Sydney"));


    • activity_maps
      <?xml version="1.0" encoding="utf-8"?>
      <RelativeLayout xmlns:android=""
      android:text="Here notification details will be display" />


Run this demo. It will look like:



You have successfully integrated Google Map in your Android app.

Now what?

Now, in the second part of this tutorial, we’ll move forward on automate location tracking process.

However, if you face any problem implementing, contact our developers for help.

While adding location-based features in your Android apps, do remember that users might have location turned off. This means you have to plan for when any user has location turned off. Still, if you need any expert to help you with building your Android app, you can hire Android app developer from us.

You can directly grab a free copy of Google map v2 demo From Github.

This page was last edited on April 9th, 2020, at 8:43.


Have an App Idea?

Get your free consultation now

Leave a Reply

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

Get Your Free Quote