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

    ETTTYGGEGERGERWG1342SFGDFG
    1 hrs
    Intermediate
    760 Learners
    4.5  (8)
    MySQL Basics
    5 hrs
    Beginner
    37.5K+ Learners
    4.46  (13774)
    Introduction to Python
    4 hrs
    Beginner
    1.5K+ Learners
    4.82  (38)
    Linked List in C
    1 hrs
    Beginner
    1.1K+ Learners
    Introduction to JUnit
    2 hrs
    Beginner
    1.6K+ Learners
    4.54  (116)
    Introduction to Spring Cloud
    2 hrs
    Beginner
    726 Learners
    4.49  (59)
    Computational Thinking for Programming
    2 hrs
    Beginner
    862 Learners