In General few apps require user location, there we can enter address in a edittext field but as to get much more flexibility we can fetch the current latitude and longitude details based on user location.

 

i.e., we can fetch latitude and longitude values from gps based on location of user we fetch these values.

 

Many apps now a days like taxi apps which will show their cabs present locations based on these values and also there are many different types of usages.

 

So lets get started

Before getting further we will get values based on network provider also.

 

Now we need to check GPS is enabled or not

 

Now checking with Network

 

 

Checking with GPS

 

 

Creating FetchLocation.java File

 

 

 

 

Creating MainActivity.java File

 

Now we will fetch the methods getLatitude and getLongitude  and show output in MainActivity.java

 

 

And then

 

Creating activity_main.xml file

Here we are adding two textviews and a button to fetch values on click.

 

 

AndroidManifest.xml

 

Adding required permission in manifest file like internet and access fine location.

 

 

 

 

Output :

latlonbanner

Show Buttons
Hide Buttons
Read previous post:
Android Tutorial On Textview Marquee Animation

Close