Попробуйте использовать этот код
public class SharedPreferenceData {
private SharedPreferences settings;
private SharedPreferences.Editor editor;
private float latitude;
private longitude;
public SharedPreferenceData(Context context) {
settings=context.getApplicationContext().getSharedPreferences("MyDataFile",0);
editor=settings.edit();
}
public void PushData(float latitude, float longitude)
{
this.latitude=latitude;
this.longitude=longitude;
editor.putFloat("lat",latitude);
editor.putFloat("log",longitude);
editor.commit();
}
public float getlatitude()
{
return settings.getFloat("lat",0);
}
public float getlongitude()
{
return settings.getFloat("log",0);
}
}
Затем используйте слушатель местоположения
SharedPreferenceData data=new SharedPreferenceData(this);
LocationListener locationListenerGPS=new LocationListener() {
@Override
public void onLocationChanged(android.location.Location location) {
double latitude=location.getLatitude();
double longitude=location.getLongitude();
data.PushData((float)latitude,(float)longitude);
}
@Override
public void onStatusChanged(String provider, int status, Bundle extras) {
}
@Override
public void onProviderEnabled(String provider) {
}
@Override
public void onProviderDisabled(String provider) {
}
};