2
I wonder if there’s any way to get the last location of GPS, before I run the option to perform obtaining the current position.
public class Localization{
private GetGPSResponse delegate = null;
public void setDelegate(GetGPSResponse delegate){
this.delegate = delegate;
}
//Método que faz a leitura de fato dos valores recebidos do GPS
public void startGPS(Object local, final Context context){
final LocationManager lManager = (LocationManager) local ;
LocationListener lListener = new LocationListener() {
public void onLocationChanged(Location locat) {
if( locat != null ) {
delegate.getGPSResponse(locat);
lManager.removeUpdates(this);
}
}
@Override
public void onStatusChanged(String arg0, int arg1, Bundle arg2) {}
@Override
public void onProviderEnabled(String arg0) {}
@Override
public void onProviderDisabled(String arg0) {}
};
lManager.requestSingleUpdate(LocationManager.GPS_PROVIDER, lListener, null);
}
interface GetGPSResponse{
void getGPSResponse(Location location);
}
}
You could save the variable
Location locat
for a variable in the class. Type:public class Localization{ private Localtion lastLocat
.– Guilherme Nascimento