Skip to content

A tutorial to get the current location in your android app

Notifications You must be signed in to change notification settings

Rohan-Kumar/Get-Current-Location

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Get-Current-Location

A tutorial to get the current location in your android app

Add the library in build.gradle

compile 'com.google.android.gms:play-services:8.4.0'

Add permission in manifest

<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/>
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>

Connect to google api. Once it is connected you can get the location by LocationServices.FusedLocationApi.requestLocationUpdates() method It takes 3 parameters

  • GoogleApiClient
  • LocationRequest
  • LocationListener

LocationListener will give you a call back onLocationChanged with a Location object.

You can get the latitude by calling getLatitude() method on the location object

You can get the longitude by calling getLongitude() method on the location object

Note: You will get the location only if gps is on. For a tutorial on how to programmatically switch on gps refer this

About

A tutorial to get the current location in your android app

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages