title: How to get current location through Google API using FusedLocationProviderClient
body: <p>I want to know my current location through Google API. In the code shown below i have used <code>FusedLocationApi</code> which is deprecated and instead i should use <code>FusedLocationProviderClient</code> which i dont know how to use also i have read Android official document but didnt get to the point. Below is my <code>AndroidManifest.xml</code> and <code>MainActivity.java</code> file:</p>
  
  <p>Also i have added dependencies:</p>
  
  <pre><code>implementation 'com.google.android.gms:play-services-location:15.0.1'
  </code></pre>
  
  <p>AndroidManifest.xml</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;manifest xmlns:android="http://schemas.android.com/apk/res/android"
  package="com.example.hp.location2"&gt;
  
  &lt;uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/&gt;
  &lt;uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/&gt;
  
  &lt;application
      android:allowBackup="true"
      android:icon="@mipmap/ic_launcher"
      android:label="@string/app_name"
      android:roundIcon="@mipmap/ic_launcher_round"
      android:supportsRtl="true"
      android:theme="@style/AppTheme"&gt;
  
      &lt;meta-data
          android:name="com.google.android.gms.version"
          android:value="@integer/google_play_services_version" /&gt;
  
      &lt;activity android:name=".MainActivity"&gt;
          &lt;intent-filter&gt;
              &lt;action android:name="android.intent.action.MAIN" /&gt;
  
              &lt;category android:name="android.intent.category.LAUNCHER" /&gt;
          &lt;/intent-filter&gt;
      &lt;/activity&gt;
  &lt;/application&gt;
  
  &lt;/manifest&gt;
  </code></pre>
  
  <p>MainActivity.java</p>
  
  <pre><code>package com.example.hp.location2;
  
  import android.Manifest;
  
  import android.content.pm.PackageManager;
  import android.location.Location;
  import android.support.annotation.NonNull;
  import android.support.annotation.Nullable;
  import android.support.v4.app.ActivityCompat;
  import android.support.v7.app.AppCompatActivity;
  import android.os.Bundle;
  import android.util.Log;
  import android.widget.TextView;
  
  import com.google.android.gms.common.ConnectionResult;
  import com.google.android.gms.common.api.GoogleApiClient;
  import com.google.android.gms.location.LocationServices;
  
  public class MainActivity extends AppCompatActivity implements
      GoogleApiClient.ConnectionCallbacks, 
  GoogleApiClient.OnConnectionFailedListener {
  
  
  private static final String TAG = "MyApps-Location2";
  private GoogleApiClient mGoogleApiClient;
  private Location mLastLocation;
  private TextView mLatitudeText;
  private TextView mLongitudeText;
  
  
  @Override
  protected void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
      setContentView(R.layout.activity_main);
  
      mLatitudeText = findViewById(R.id.latitude_text);
      mLongitudeText = findViewById(R.id.longitude_text);
  
      mGoogleApiClient = new GoogleApiClient.Builder(this)
              .addOnConnectionFailedListener(this)
              .addConnectionCallbacks(this)
              .addApi(LocationServices.API)
              .build();
  }
  
  @Override
  protected void onStart() {
      super.onStart();
      mGoogleApiClient.connect();
      Log.i(TAG, "GoogleApiClient Connected");
  }
  
  @Override
  protected void onStop() {
      super.onStop();
  
      if (mGoogleApiClient.isConnected()) {
          mGoogleApiClient.disconnect();
          Log.i(TAG, "GoogleApiClient DisConnected");
      }
  }
  
  @Override
  public void onConnected(@Nullable Bundle bundle) {
  
      if (ActivityCompat.checkSelfPermission(this, Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED &amp;&amp; ActivityCompat.checkSelfPermission(this, Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED) {
          // TODO: Consider calling
          //    ActivityCompat#requestPermissions
          // here to request the missing permissions, and then overriding
          //   public void onRequestPermissionsResult(int requestCode, String[] permissions,
          //                                          int[] grantResults)
          // to handle the case where the user grants the permission. See the documentation
          // for ActivityCompat#requestPermissions for more details.
          return;
      }
      mLastLocation = LocationServices.FusedLocationApi.getLastLocation(mGoogleApiClient);
      if(mLastLocation != null) {
          mLatitudeText.setText(String.valueOf(mLastLocation.getLatitude()));
          mLongitudeText.setText(String.valueOf(mLastLocation.getLongitude()));
      }
  
  }
  
  @Override
  public void onConnectionSuspended(int i) {
      Log.i(TAG, "onConnectionSuspended");
  }
  
  @Override
  public void onConnectionFailed(@NonNull ConnectionResult connectionResult) {
      Log.i(TAG, "onConnectionFailed");
  }
  }
  </code></pre>
  
  <p>It would be great if i get working code.</p>
  
  <p>Thank You</p>