1

I am trying to use google maps api v2 to log the location of the user and store it into a SQLite db. I have managed to do this. But now the problem occurs as my location data is only being logged once. Once the user presses a button, the location is supposed to be logging continuously until the user presses another button. However, in my case; the app logs the location the moment the user presses the button and that's it. The location is logged ONLY ONCE. I have tried to manipulate the time using the mLocationRequest handle but changing the time there has no effect; my data is only being logged once. Can someone help me out, please?

private void handleNewLocation(Location location) {

    String key = "xx";
    double currentLatitude = location.getLatitude();
    double currentLongitude = location.getLongitude();
    LatLng latLng = new LatLng(currentLatitude, currentLongitude);

    Log.d("location", String.valueOf(latLng));
    databaseHandler.enterMapValues( _workOutId,String.valueOf(latLng));
       // Log.d("location new ", String.valueOf(latLng));

    old_longitude = currentLongitude;
    old_latitude = currentLatitude;
}

This function is used to get new location. I am calling this in onConnected:

public void onConnected(Bundle bundle) {

    Log.i(TAG, "location services connected");
    location_current = LocationServices.FusedLocationApi.getLastLocation(mGoogleApiClient); //to get last location


    if (location_current == null) { //if last location is null, only then it will request new location
        LocationServices.FusedLocationApi.requestLocationUpdates(mGoogleApiClient, mLocationRequest, this);
    } else {
        handleNewLocation(location_current);

    }

}
Richeek Dey
  • 257
  • 2
  • 15

1 Answers1

0

I removed the if-else in onConnected. Now it fetches location every 5 seconds, since thats the time specified in mLocationRequest in onCreate(). This solves my issue.

Richeek Dey
  • 257
  • 2
  • 15