title: How to get users location bounding box from google fit api
body: <p>I'm trying to get the users step count and location bounding box in the last 24 hours from google fit API.</p>
  
  <p>I don't have a problem with the step count but i'm getting an error for the location.</p>
  
  <p>CODE: </p>
  
  <pre><code>@Override
  protected void onStart() {
      super.onStart();
      if (mGoogleApiClient == null) {
          mGoogleApiClient = new GoogleApiClient.Builder(this)
                  // Optionally, add additional APIs and scopes if required.
                  .addApi(Fitness.API)
                  .addScope(new Scope(Scopes.FITNESS_LOCATION_READ))
                  .addScope(new Scope(Scopes.FITNESS_ACTIVITY_READ))
                  .addConnectionCallbacks(this)
                  .addOnConnectionFailedListener(this)
                  .build();
      }
      mGoogleApiClient.connect();
  } 
  
  private class getFitnessTask extends AsyncTask&lt;Void, Void, String&gt; {
      @Override
      protected String doInBackground(Void... params) {
  
          Log.e("getFitnessTask", "getFitnessTask");
          getStepsToday();
          getLocation();
          return null;
      }
  
      @Override
      protected void onPostExecute(String s) {
  
      }
  }
  
  private void getStepsToday() {
      Calendar cal = Calendar.getInstance();
      Date now = new Date();
      cal.setTime(now);
      long endTime = cal.getTimeInMillis();
      cal.set(Calendar.HOUR_OF_DAY, 0);
      cal.set(Calendar.MINUTE, 0);
      cal.set(Calendar.SECOND, 0);
      long startTime = cal.getTimeInMillis();
  
      final DataReadRequest readRequest = new DataReadRequest.Builder()
              .read(DataType.TYPE_STEP_COUNT_DELTA)
              .setTimeRange(startTime, endTime, TimeUnit.MILLISECONDS)
              .build();
  
      DataReadResult dataReadResult =
              Fitness.HistoryApi.readData(mGoogleApiClient, readRequest).await(1, TimeUnit.MINUTES);
  
      DataSet stepData = dataReadResult.getDataSet(DataType.TYPE_STEP_COUNT_DELTA);
  
      int totalSteps = 0;
  
      for (DataPoint dp : stepData.getDataPoints()) {
          for(Field field : dp.getDataType().getFields()) {
  
              int steps = dp.getValue(field).asInt();
              totalSteps += steps;
  
          }
      }
  
      Log.e("FITNES", "total steps: " + totalSteps);
  }
  
  private void getLocation() {
      Calendar cal = Calendar.getInstance();
      Date now = new Date();
      cal.setTime(now);
      long endTime = cal.getTimeInMillis();
      cal.set(Calendar.HOUR_OF_DAY, 0);
      cal.set(Calendar.MINUTE, 0);
      cal.set(Calendar.SECOND, 0);
      long startTime = cal.getTimeInMillis();
  
      final DataReadRequest readRequest = new DataReadRequest.Builder()
              .read(DataType.TYPE_STEP_COUNT_DELTA)
              .setTimeRange(startTime, endTime, TimeUnit.MILLISECONDS)
              .build();
  
      DataReadResult dataReadResult =
              Fitness.HistoryApi.readData(mGoogleApiClient, readRequest).await(1, TimeUnit.MINUTES);
  
      DataSet locationData = dataReadResult.getDataSet(DataType.AGGREGATE_LOCATION_BOUNDING_BOX);
  
      Log.e("FIT", locationData.toString());
      int totalSteps = 0;
  
      for (DataPoint dp : locationData.getDataPoints()) {
          for(Field field : dp.getDataType().getFields()) {
  
              Log.e("FITNES", field.toString());
  
          }
      }
  
  }
  </code></pre>
  
  <p>i get the erorr in this:</p>
  
  <pre><code>DataSet locationData = dataReadResult.getDataSet(DataType.AGGREGATE_LOCATION_BOUNDING_BOX);
  </code></pre>
  
  <blockquote>
    <p>Caused by: java.lang.IllegalArgumentException:
    Attempting to read data for com.google.location.bounding_box, which
    was not requested</p>
  </blockquote>
  
  <p>So What is missing? How can i get the location bounding box?
  Thanks</p>