如何在Android中获取以前的位置?我正在尝试制作一个每 30 秒更新一次位置的应用程序,我想通过查找先前位置和当前位置之间的距离来测量我的旅行量。但是,我只能获得当前位置。这是我的代码
public void onCreate(Bundle savedInstanceState)
{ //This is for the UI
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
showData = (TextView)findViewById(R.id.showText);
start = (Button)findViewById(R.id.startButton);
stop = (Button)findViewById(R.id.stopButton);
start.setOnClickListener(globalListener);
stop.setOnClickListener(globalListener);
//This is for the Location
locationManager = (LocationManager)getSystemService(LOCATION_SERVICE);
location = locationManager.getLastKnownLocation(LocationManager.GPS_PROVIDER);
locationManager.requestLocationUpdates(locationManager.GPS_PROVIDER,10,10,this);
}
public void onLocationChanged(Location location)
{
distance = location.distanceTo(previousLocation);
meter = distance + meter;
showData.setText(Double.toString(meter));
}
public void onStatusChanged(String provider, int status, Bundle extras) {
//To change body of implemented methods use File | Settings | File Templates.
}
public void onProviderEnabled(String provider) {
//To change body of implemented methods use File | Settings | File Templates.
}
public void onProviderDisabled(String provider) {
//To change body of implemented methods use File | Settings | File Templates.
}