0

I am trying to get the location of the device and update to database continuously... However i just want to run that process in the background and update the location to the database in web server

// Acquire a reference to the system Location Manager

LocationManager locationManager = (LocationManager) this.getSystemService(Context.LOCATION_SERVICE);
    // Define a listener that responds to location updates
    LocationListener locationListener = new LocationListener() {
        public void onLocationChanged(Location location) {
          // Called when a new location is found by the network location provider.makeUseOfNewLocation(location);
            double latitude=location.getLatitude();
            givenlatitude=String.valueOf(latitude);
            double longitude=location.getLongitude();
            Toast.makeText(getApplicationContext(),String.valueOf(latitude)+ " " +String.valueOf(longitude) , Toast.LENGTH_SHORT).show();
        }

        public void onStatusChanged(String provider, int status, Bundle extras) {}

        public void onProviderEnabled(String provider) {}

        public void onProviderDisabled(String provider) {}
      };

    // Register the listener with the Location Manager to receive location updates
    locationManager.requestLocationUpdates(LocationManager.NETWORK_PROVIDER, MINIMUM_TIME_BETWEEN_UPDATES, 1.0f, locationListener);
    `

This is how i have been getting the location on interval time... i just want to run this code in the background and update it to the database peroidically!!!

ABC
  • 15
  • 1
  • 1
  • 6

0 Answers0