我有这个:
public class GpsUpdate extends Observable implements LocationListener {
private int x_position;
private int y_position;
private float currentAccuracy;
public GpsUpdate(Observer observer){
addObserver(observer);
}
@Override
public void onLocationChanged(Location location) {
int lat = (int) (location.getLatitude() * 1E6);
int lng = (int) (location.getLongitude() * 1E6);
setAccuracy(location.getAccuracy());
setX_position(lat);
setY_position(lng);
setChanged();
notifyObservers();
}
@Override
public void onProviderDisabled(String provider) {
}
@Override
public void onProviderEnabled(String provider) {
}
@Override
public void onStatusChanged(String provider, int status, Bundle extras) {
}
public int getX_position() {
return x_position;
}
public void setX_position(int x_position) {
this.x_position = x_position;
}
public int getY_position() {
return y_position;
}
public void setY_position(int y_position) {
this.y_position = y_position;
}
public void setAccuracy(float currentAccuracy) {
this.currentAccuracy = currentAccuracy;
}
public float getAccuracy(){
return currentAccuracy;
}
}
此方法 (onLocationChanged()) 通知其他类中的另一个方法 (update()) 位置已更改,但即使当前与以前相同,我也需要收集所有坐标。
_GPSUPDATE = new GpsUpdate(this);
locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 1000, 1, _GPSUPDATE);
@Override
public void update(Observable observable, Object data) {
xCurrent = _GPSUPDATE.getX_position();
yCurrent = _GPSUPDATE.getY_position();
.....
}
那么,我要添加/更改什么才能每秒获得位置?