我想我的代码等待mGPS.GotLocaton为真(时设置onLocationChanged事件被触发)等待被设置为true
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);
但它不会等待/循环 - 我错过了什么。
看起来像Android代码所以增加了Android标签 –