【发布时间】:2012-06-16 14:09:47
【问题描述】:
我希望我的代码等待 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);
但它不会等待/循环 - 我错过了什么。
【问题讨论】:
-
看起来像 Android 代码所以添加了 android 标签
标签: android gps location wait android-location