I have this below code which get the Most Recent location after every 30 seconds and 10 meters, but it will constantly keep on receiving the location updates and it picks up the most recent location updates after every 30 seconds.
Is there any better/efficient way to do this?
Basically my requirement is to make use of the Current Location after every 30 seconds and 10 meters distance moved. I can do this in several ways, I was thinking is there any better way to do this problem? And what about Timer class?
Any thoughts will be of great help.
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
locationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
locationListener = new GPSLocationListener();
locationManager.requestLocationUpdates(
LocationManager.GPS_PROVIDER,
30000,
10,
locationListener);
}
Below is the class that implements LocationListener.
private class GPSLocationListener implements LocationListener {
@Override
public void onLocationChanged(Location location) {
if (location != null) {
GeoPoint point = new GeoPoint(
(int) (location.getLatitude() * 1E6),
(int) (location.getLongitude() * 1E6));
System.out.println(location.getLatitude()+"--"+location.getLongitude());
}
}
@Override
public void onProviderDisabled(String provider) {
}
@Override
public void onProviderEnabled(String provider) {
}
@Override
public void onStatusChanged(String provider, int status, Bundle extras) {
}
}