等待LocationClient回调

时间:2013-06-18 08:58:43

标签: java android callback

我正在尝试编写简单的方法来通过Google Play服务获取位置。像这样的东西(是的,它可能还有其他一些问题..):

Location getLastLocation() {
    final Location location = new Location("");
    locationClient.registerConnectionCallbacks(new GooglePlayServicesClient.ConnectionCallbacks() {
        @Override
        public void onConnected(final Bundle connectionHint) {
            location.set(locationClient.getLastLocation());
            locationClient.unregisterConnectionCallbacks(this);
            locationClient.disconnect();
        }

        @Override
            public void onDisconnected() {};
        });
    if (!locationClient.isConnecting() || !locationClient.isConnected()) {
        locationClient.connect();
    }
    return location;
}
显然,它将返回空Location。那么,我怎样才能让它等待回调完成?当然,没有阻止主线程....

0 个答案:

没有答案