title: How to get device location
body: <p>So, I'm trying to build a weather app for practice and I've been running into the problem of trying to get the location. I've read people suggest to use getLastLocation through the fused location API, problem with that is if they don't already have a location registered on the device it comes up null. I've noticed using the emulator times that this come up is rare, but I'd still like my app to handle it properly. One instance where you might run into this is if they just turned GPS off and back on, or if the phone was just turned on. One thing I did was if getLastLocation does come back null, is to request an update, but then you still have to wait for the device to register an updated location, which with a weather app all of the data is based off of and you're still kind of running into the same problem. I've noticed with other apps this isn't a problem, like sometimes I actually have to load up Google Maps to get it to register a location. How does Google Maps force it to update the location? Here's the example from my getLocation method:</p>
  
  <pre><code>public void getLocation() throws SecurityException {
      boolean gps_enabled;
      LocationManager lm = (LocationManager) this.getSystemService(Context.LOCATION_SERVICE);
      gps_enabled = lm.isProviderEnabled(LocationManager.GPS_PROVIDER);
      if (gps_enabled) {
  
          Location location = LocationServices.FusedLocationApi.getLastLocation(mGoogleApiClient);
          if (location != null) {
              startGetForecast(location);
          } else {
              LocationRequest request = LocationRequest.create();
              request.setNumUpdates(1);
              request.setPriority(LocationRequest.PRIORITY_HIGH_ACCURACY);
              LocationServices.FusedLocationApi.requestLocationUpdates(mGoogleApiClient, request, this);
          }
      } 
      else {
          AlertDialogFragment alertDialogFragment = new AlertDialogFragment();
          alertDialogFragment.setErrorTexts("Location Unavailable", "Could not retrieve location information.", "Exit");
          alertDialogFragment.show(getSupportFragmentManager(), "Location Unavailable");
      }
  }
  </code></pre>