我希望我的代码等待 mGPS.GotLocaton 为真(在触发 onLocationChanged 事件时设置)
public class GPSManager {
Context MyContext;
boolean GotLocation = false;
Location CurrentLocation;
LocationManager locationManager;
LocationListener locationlistener = new LocationListener() {
public void onLocationChanged(Location location) {
// Called when a new location is found by the network location provider.
GotLocation = true;
locationManager.removeUpdates(locationlistener);
}
public void onStatusChanged(String provider, int status, Bundle extras) {}
public void onProviderEnabled(String provider) {}
public void onProviderDisabled(String provider) {}
};
public GPSManager(Context context){
this.MyContext = context;
locationManager = (LocationManager) MyContext.getSystemService(Context.LOCATION_SERVICE);
}
public void GetCurrentLocation(){
locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 0, 0, locationlistener);
GotLocation = false;
}
}
被调用:
myGPS.GetCurrentLocation();
do{
}while (!myGPS.GotLocation);
但它不会等待/循环 - 我错过了什么。