title: Android Fused Location API. Location Always null
body: <p>I am trying to implement fused location for getting the current location.
  I am doing it with the help of this <a href="http://javapapers.com/android/android-location-fused-provider/" rel="nofollow noreferrer">link</a></p>
  
  <p>My googleAPiCLient is connected. But location is always null</p>
  
  <p>In my Manifest file I have put this </p>
  
  <pre><code>   &lt;meta-data android:name="com.google.android.gms.version"
          android:value="5089000" /&gt;
  </code></pre>
  
  <p>I created a seperate Fusionclass.</p>
  
  <p>MY fusion class-- </p>
  
  <pre><code>import java.util.concurrent.Executors;
  import java.util.concurrent.TimeUnit;
  
  import android.app.Activity;
  import android.location.Location;
  import android.os.Bundle;
  import android.util.Log;
  
  import com.XXX.constants.LogConstants;
  import com.google.android.gms.common.ConnectionResult;
  import com.google.android.gms.common.api.GoogleApiClient;
  import com.google.android.gms.location.FusedLocationProviderApi;
  import com.google.android.gms.location.LocationRequest;
  import com.google.android.gms.location.LocationServices;
  
  public class FusedLocation implements 
          GoogleApiClient.ConnectionCallbacks,
          GoogleApiClient.OnConnectionFailedListener {
  
  
  
  private static final long INTERVAL = 1000 * 30;
      private static final long FASTEST_INTERVAL = 1000 * 5;
      private static final long ONE_MIN = 1000 * 60;
      private static final long REFRESH_TIME = ONE_MIN * 5;
  //  private static final float MINIMUM_ACCURACY = 50.0f;
      Activity LauncherActivity; 
      private LocationRequest locationRequest;
      private GoogleApiClient googleApiClient;
      private Location location;
      private FusedLocationProviderApi fusedLocationProviderApi = LocationServices.FusedLocationApi;
  public FusedLocation(Activity LauncherActivity) {
      locationRequest = LocationRequest.create();
  //  locationRequest.setPriority(LocationRequest.PRIORITY_HIGH_ACCURACY);
      locationRequest.setInterval(INTERVAL);
      locationRequest.setFastestInterval(FASTEST_INTERVAL);
      this.LauncherActivity = LauncherActivity;
  
      googleApiClient = new GoogleApiClient.Builder(LauncherActivity)
              .addApi(LocationServices.API).addConnectionCallbacks(this)
              .addOnConnectionFailedListener(this).build();
  
      if (googleApiClient != null) {
           Log.i(LogConstants.INFO_LOG, "googleApiClient is not null");
    //the console prints this
          googleApiClient.connect();
  
      }
  }
  
  @Override
  public void onConnected(Bundle connectionHint) {
       Log.i(LogConstants.INFO_LOG, "GoogleApiClient connected");
      Location currentLocation = fusedLocationProviderApi.getLastLocation(googleApiClient);
      if (currentLocation != null &amp;&amp; currentLocation.getTime() &gt; REFRESH_TIME) {
          location = currentLocation;
      } else {
            fusedLocationProviderApi.requestLocationUpdates(googleApiClient,locationRequest, locListen);
          // Schedule a Thread to unregister location listeners
          Executors.newScheduledThreadPool(1).schedule(new Runnable() {
              @Override
              public void run() {
                  fusedLocationProviderApi.removeLocationUpdates(googleApiClient, locListen);
              }
          }, ONE_MIN, TimeUnit.MILLISECONDS);
      }
  }
  
  
  
  
   com.google.android.gms.location.LocationListener locListen=new           com.google.android.gms.location.LocationListener() {
  
      @Override
      public void onLocationChanged(Location location) {
  
           Log.i(LogConstants.INFO_LOG, "75location::"+location);
  
  
  
      }
  };
  
  public Location getLocation() {
      return this.location;
  }
  
  @Override
  public void onConnectionSuspended(int i) {
  
  }
  
  @Override
  public void onConnectionFailed(ConnectionResult connectionResult) {
  
  }
  </code></pre>
  
  <p>}</p>
  
  <p>My activity class I am calling the FusedLOcation class from the <code>oncreate</code></p>
  
  <pre><code> //show error dialog if GoolglePlayServices not available
      if (!isGooglePlayServicesAvailable()) {
          finish();
      }
      fusedLocation = new FusedLocation(this);
      Location location = fusedLocation.getLocation();
      String locationResult = "";
      if (null != location) {
          Log.i(LogConstants.INFO_LOG, location.toString());
          double latitude = location.getLatitude();
          double longitude = location.getLongitude();
          Log.i(LogConstants.INFO_LOG, "longitude::!"+longitude);
          float accuracy = location.getAccuracy();
          /*double elapsedTimeSecs = (double) location.getElapsedRealtimeNanos()
                  / 1000000000.0;*/
          String provider = location.getProvider();
          double altitude = location.getAltitude();
          locationResult = "Latitude: " + latitude + "\n" +
                  "Longitude: " + longitude + "\n" +
                  "Altitude: " + altitude + "\n" +
                  "Accuracy: " + accuracy + "\n" +
                  "Elapsed Time: "  + " secs" + "\n" +
                  "Provider: " + provider + "\n";
      } else {
          locationResult = "Location Not Available!";
          Log.i(LogConstants.INFO_LOG, "Location Not Available!");
      }
  
   private boolean isGooglePlayServicesAvailable() {
          int status = GooglePlayServicesUtil.isGooglePlayServicesAvailable(this);
          Log.i(LogConstants.INFO_LOG, "status:"+status);
          if (ConnectionResult.SUCCESS == status) {
              return true;
          } else {
              GooglePlayServicesUtil.getErrorDialog(status, this, 0).show();
              return false;
          }
      }
  </code></pre>
  
  <p>Location is always null. The listeners do not seem to be working.</p>