Look at the documentation here.
The time is milliseconds, so for 5 minutes minimum, you should write (5mn*60s*1000ms = 300000ms):
locationManager.requestLocationUpdates(LocationManager.NETWORK_PROVIDER, 300000, 0, locationListener);
Pergunta
Hey all I am using the following code in order to get my current LAT and LONG:
try{
locationManager = (LocationManager) this.getSystemService(Context.LOCATION_SERVICE);
locationListener = new LocationListener() {
public void onLocationChanged(Location location) {
longitude=location.getLongitude();
latitude=location.getLatitude();
Toast.makeText(MainActivity.this, "Your Current location is"+"\n"+"Longitude : "+longitude+"\n"+"Latitude : "+latitude, Toast.LENGTH_LONG).show();
}
public void onStatusChanged(String provider, int status, Bundle extras) {}
public void onProviderEnabled(String provider) {}
public void onProviderDisabled(String provider) {}
};
locationManager.requestLocationUpdates(LocationManager.NETWORK_PROVIDER, 0, 0, locationListener);
}catch(Exception e){
longitude=0.0;
latitude=0.0;
}
Works just fine but it seems to update every 30 seconds or so. How can i modify the code above to only update every 5 minutes?
I tried:
locationManager.requestLocationUpdates(LocationManager.NETWORK_PROVIDER, 0, 10, locationListener);
And that seems to update it every 6 minutes? So does 10 = 6 minutes here and therefore 9 would = 5 minutes?
Solução
Look at the documentation here.
The time is milliseconds, so for 5 minutes minimum, you should write (5mn*60s*1000ms = 300000ms):
locationManager.requestLocationUpdates(LocationManager.NETWORK_PROVIDER, 300000, 0, locationListener);