Before we create the location client, implement the interfaces that Location Services uses to communicate with our app: Reference : https://developer.android.com/training/location/3.Retrieving Location Updates : To get periodic location updates from location services, we send a request using a location client.Note : Make sure Google Play services is properly installed and working in our device.Please don’t test this location API in an emulator as this does not work.Google Maps has today announced a new feature to allow you to share your location with others.While that might seem creepy, it’s not the first to add this type of functionality.Android has two location permissions, ACCESS_COARSE_LOCATION and ACCESS_FINE_LOCATION.The permissions that we choose affects the accuracy of the location updates we receive.
Location Request : A data object that contains quality of service parameters for requests to the Location Client 4. After connecting location Client, we are able to get location 2. Retrieving the location update at particular time interval or particular distance or both. Connecting Location Client to Google API: // Create a new global location parameters object Location Request m Location Request = Location Request.create(); //Set the update interval m Location Interval(Location Utils.Location Service Callbacks : Before we request location updates, we must first implement the interfaces that Location Services uses to communicate connection status to our app: 4.1com.google.common. Connection Callbacks: Specifies methods that Location Services calls when a location client is connected or disconnected 4.2com.google.common. On Connection Failed Listener : Specifies a method that Location Services calls if an error occurs while attempting to connect the location client. UPDATE_INTERVAL_IN_MILLISECONDS); // Use high accuracy m Location Priority(Location Request.PRIORITY_HIGH_ACCURACY); /** * Location Client(arg1, arg2 , arg3) * arg1 : Context * arg2 : Connection Callbacks * arg3 : On Connection Failed Listener **/ Location Client m Location Client = new Location Client(arg1, arg2 , arg3); m Location Client.connect(); /** * Note: connect() method will take some time.There’s even a new maps app designed specifically for people following each others’ cars on long road trips.The new feature is available now but you’ll need to set it up for each individual.