How To Get Current Phone Location in Android

In this tutorial I am going to show you how to can get your current location on your android phone. To get the phone location you need to enable your phone GPS.  There are two types of location provider:

  1. GPS Location Provider.
  2. Network Location Provider.

 

GPS VS Network Location Provider.

  • Network Location Provider is faster than GPS location provider.
  • GPS is very very slow in Door and consumes more battery.
  • Network Location Provider depends on nearest cell tower.
  • GPS location Provider will give you accurate location.

Building Android Application

  • Add the manifest permission for accessing phone location.

       manifest.xml

 

 

  • Add the layout file with textview so that u can display longitude and latitude.

activity_main.xml

 

android current location

  • Add the MainActivity.java file which consist of location code i.e to get the location of the user. This code will work on Marshmallow since runtime permission are handled.

MainActivity.java

 

  • That’s it guys, now you can get your current location. Please turn on GPS and mobile data that’s it.

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.