I have used GPS in measuring distance traveled.The problem is GPS sometimes do not update location change for a long time.
Is there any solution for this?
locationListen = new LocationListener() { public void onLocationChanged(Location currentLocation) { if (prevLocation != null){ test = currentLocation.distanceTo(prevLocation); distance+=test; } prevLocation = currentLocation; } public void onStatusChanged(String provider, int status, Bundle b) { switch (status) { case LocationProvider.OUT_OF_SERVICE: Toast.makeText(MainActivity.this, "Status Changed: Out of Service " + provider, Toast.LENGTH_SHORT).show(); break; case LocationProvider.TEMPORARILY_UNAVAILABLE: Toast.makeText( MainActivity.this, "Status Changed: Temporarily Unavailable " + provider, Toast.LENGTH_SHORT).show(); break; case LocationProvider.AVAILABLE: Toast.makeText(MainActivity.this, "Status Changed: Available " + provider, Toast.LENGTH_SHORT).show(); break; } } public void onProviderDisabled(String s) { } public void onProviderEnabled(String s) { } }; startOperation.setOnClickListener(new OnClickListener() { @Override public void onClick(View but) { if (startOperation.getText().equals("Start Calculating Fare")) { mHandler.post(run); myManager.requestLocationUpdates( LocationManager.GPS_PROVIDER, 1000, 10, locationListen); startOperation.setText("Stop the calculations"); } else { mHandler.removeCallbacks(run); myManager.removeUpdates(locationListen); finalInfos(); } } });
My code for the location listener. It just update using GPS. As what I am saying the GPS is sometimes too long to detect a location