Android

Location Based Services

Location Based Services

Android provides several location APIs that you can use to build applications that mainly focus on location. In this section, we are going to understand how to use Location Services in your Application. 
To get the current location on your application, you need to create a location client with the help of the LocationClient object. The location client needs to be connected to location services with the help of connect() method and then it is called using the getLastLocation() method. 
There are two interfaces that you need to implement the location functionality in your application:

  • GooglePlayServicesClient.OnConnectionFailedListener
  • GooglePlayServicesClient.ConnectionCallbacks

These two interfaces provide some important callbacks method that includes:

  • abstract void onDisconnected(): This method is called after it gets disconnected from the client. To disconnect from the location client, the disconnect() method is used. 
  • abstract void onConnected(Bundle connectionHint): This callback method is called after the successful connection of the location client with the location service. 
  • abstract void onConnectionFailed(ConnectionResult result): It is called when there occurs an error while connecting the client to the location service. 

Top course recommendations for you

    Career Kickstarter Challenge in Software Development
    1 hrs
    Advanced
    70 Learners
    ETTTYGGEGERGERWG1342SFGDFG
    1 hrs
    Intermediate
    738 Learners
    4.33  (6)
    HTML Tutorial
    6 hrs
    Beginner
    9.7K+ Learners
    4.52  (2654)
    GitHub Tutorial for Beginners
    2 hrs
    Beginner
    1.5K+ Learners
    4.42  (842)
    MySQL Basics
    5 hrs
    Beginner
    32.4K+ Learners
    4.45  (11084)
    Introduction to Python
    4 hrs
    Beginner
    1.4K+ Learners
    4.78  (32)
    Linked List in C
    1 hrs
    Beginner
    738 Learners
    Introduction to JUnit
    2 hrs
    Beginner
    1.2K+ Learners
    4.62  (66)
    Introduction to Spring Cloud
    2 hrs
    Beginner
    485 Learners
    4.5  (14)
    Computational Thinking for Programming
    2 hrs
    Beginner
    504 Learners