title: How to be sure to get gps location each time you ask
body: <p>In my app, people post ads that others can see. They are filtred using the distance between the creator of the annonce and the guy reading it. 
  If someone post an ad, I need to be sure to get his location. If someone looks for an ad, I need to be sure to get his location to sorts the ads. </p>
  
  <p>In my code, I have a way to get location but it sometimes return null. </p>
  
  <p>Here is the little code (I've checked permission etc)</p>
  
  <pre><code> FusedLocationProviderClient mFusedLocationProviderClient;
      mFusedLocationProviderClient = LocationServices.getFusedLocationProviderClient(context);
  
      try{
          if(mLocationPermissionsGranted){
              final Task location = mFusedLocationProviderClient.getLastLocation();
              location.addOnCompleteListener(new OnCompleteListener() {
                  @Override
                  public void onComplete(@NonNull Task task) {
                      if(task.isSuccessful()){
                          Log.d(TAG, "onComplete: found location!");
  
                          Location currentLocation = (Location) task.getResult();
  
                          if (currentLocation != null)
                          {
                              double Latit = currentLocation.getLatitude();
                              double Longit = currentLocation.getLongitude();
  
                              LatLng latLong = new LatLng(Latit, Longit);
                          //TODO do something with latlong
                          }
                      }else{
                          Log.d(TAG, "onComplete: current location is null");
                          Toast.makeText(context, "unable to get current location", Toast.LENGTH_SHORT).show();
  
  
  
  
                      }
                  }
              });
          }
      }catch (SecurityException e){
          Log.e(TAG, "getDeviceLocation: SecurityException: " + e.getMessage() );
      }
  </code></pre>
  
  <p>But sometimes, the <code>Location currentLocation = (Location) task.getResult();</code> return null even if the task is sucessefull. I don't really know why.
  I would like to know if there is a reliable way to get the location whenever I ask it (it location is enabled on the phone of course). 
  Thank you </p>