【问题标题】:Google Places API for Android resulting ERROR_OPERATION_FAILED用于 Android 的 Google Places API 导致 ERROR_OPERATION_FAILED
【发布时间】:2015-09-12 04:34:19
【问题描述】:

所以我现在遇到的问题是,当我使用 AutoComplete 方法时,如何从 Google Places 搜索中获取结果?目前发生的一切就是我得到这个错误 aAutocompletePredictionBuffer{status=Status{statusCode=ERROR_OPERATION_FAILED, resolution=null}}

这是我尝试执行请求的代码 sn-p。这也是基于我在互联网上找到的示例。

void someMethod(){
client = new GoogleApiClient.Builder(this)
                .addApi(Places.GEO_DATA_API)
                .enableAutoManage(this, 0, this)
                .addConnectionCallbacks(this)
                .useDefaultAccount()
                .build();

        client.connect();
}

 @Override
    public void onConnected(Bundle bundle) {
        PendingResult<AutocompletePredictionBuffer> callback = Places.GeoDataApi.getAutocompletePredictions(client,
                "Chicago",
                googleMap.getProjection().getVisibleRegion().latLngBounds,
                null);

        callback.setResultCallback(result ->{
            result.toString();
        });
    }

如您所见,我构建了 API,然后在它连接时发出请求。但是我得到的只是这个错误。任何帮助将不胜感激!谢谢

【问题讨论】:

    标签: java android api google-maps google-places-api


    【解决方案1】:

    事实证明,当您使用自动完成时,您无法使用显示的 GoogleMap 的默认缩放。你需要有一个专注于一个大陆或国家的项目。所以我最终只是简单地请求用户的当前位置,然后在该位置上平移相机以获得视口,这样我就可以获得纬度边界。 (使用处理程序等待)

    client = new GoogleApiClient.Builder(this)
                    .enableAutoManage(this, 0 /* clientId */, this)
                    .addApi(Places.GEO_DATA_API)
                    .addApi(Places.PLACE_DETECTION_API)
                    .build();
    
            client.connect();
    
            Handler handler = new Handler();
            handler.postDelayed(()->{
                PendingResult<PlaceLikelihoodBuffer> currentlocation = Places.PlaceDetectionApi.getCurrentPlace(client, null);
    
                currentlocation.setResultCallback(place -> {
    
    
                    CameraUpdate cameraUpdate = CameraUpdateFactory.newLatLngZoom(place.get(0).getPlace().getLatLng(), 10);
                    googleMap.moveCamera(cameraUpdate);
    
                    handler.postDelayed(() -> {
                        PendingResult<AutocompletePredictionBuffer> callback = Places.GeoDataApi
                                .getAutocompletePredictions(client, "Chicago",
                                        googleMap.getProjection().getVisibleRegion().latLngBounds, null);
    
                        callback.setResultCallback(result -> {
                            result.toString();
                        });
                    }, 1000);
    
    
                });
    
    
            }, 1000);
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2019-09-24
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多