Android Get Current Location Latitude And Longitude Tutorial Example

By | July 24, 2019

Android Current Location Latitude Longitude Example Tutorial

What is Location Listener in Android ?

Location Listener is Used to receiving notifications from the LocationManager when the location has changed. These methods are called is LocationListener has been registered with the location manager service. 

Location class is geographic location. It contains latitude and longitude etc.

Location Manager is provide the access system is Location Service.

Location object represents a geographic location it can consist a latitude, longitude, time stamp, and other information such as bearing, altitude and velocity.



In this Tutorial to Create Get the current location using location listener.And Get the current latitude and longitude in the location listener.How to get the current location in android to implements Location Listener and some Methods are implements and then get the location without Google API used.

In this Example i have not Google API used.I have a used to Location listener in android built in package and get the current location.

Methods of Location Object Class

distanceTo(Location location) : It is used to distance in meters between this location.

getAccuracy() : It is used to Get the estimated accuracy of this location, in meters.

getAltitude() : In this Method is used to Get the altitude if available, in meters above sea level.

getLatitude() : In this method is used to Get the latitude, in degrees.

getLongitude() : In this method is used to  Get the longitude, in degrees.

getBearing() : In this Method is used to Get the bearing, in degrees.

getSpeed() : In this method is used to Get the speed if it is available, in meters/second over ground.

setLatitude(double latitude) : In this method is used to Set the latitude, in degrees.

setLongitude(double longitude) : In this Method is used to Set the longitude, in degrees.



Implements Methods of Location Listener

onLocationChanged(Location location) : In this Method is Called when the location has been changed.

onProviderDisabled(String provider) : In this Method is Called when the provider is disabled by the user.

onProviderEnabled(String provider) : In this Method is Called when the provider is enabled by the user.

onStatusChanged(String provider,int status,Bundle bundle) : In this method is Called when the provider status changes.



Implements LocationManager Type

LocationManager.GPS_PROVIDER : In this Type used to location using satellites. this provider return a location fix.

LocationManager.NETWORK_PROVIDER : In this Type used to location based on the availability of nearby cell towers and WiFi access points. This is faster than GPS_PROVIDER.

It is used to implements methods and Types of Location and you can used to different different methods and type implements to get the current location.



How to Get Current Location Latitude And Longitude Example

Declared Permission in AndroidManifest.xml File.

Create activity_main.xml File Follow this Code.



Create MainActivity.java File Follow this Code.

Android Get Current Location Latitude And Longitude Tutorial Example

Above the Example of Create Simple Get Current Location using Location Listener. In this example to declared some permission and then check the runtime permission in location. you can display the permission allow or deny and then fetch the current location in your device and then display the textView in latitude and longitude.