我想我的代碼等待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標籤 –