【问题标题】:use PlaceDetectionApi to detect place get INTERNAL_ERROR使用 PlaceDetectionApi 检测地点得到 INTERNAL_ERROR
【发布时间】:2016-01-20 05:32:43
【问题描述】:

我使用谷歌地图检测当前位置但出错 这是我的代码:

private void initGoogleApiClient() {
    mGoogleApiClient = new GoogleApiClient
            .Builder(this)
            .enableAutoManage(this, 0, new GoogleApiClient.OnConnectionFailedListener() {
                @Override
                public void onConnectionFailed(ConnectionResult connectionResult) {

                }
            })
            .addApi(Places.GEO_DATA_API)
            .addApi(Places.PLACE_DETECTION_API)
            .addConnectionCallbacks(new GoogleApiClient.ConnectionCallbacks() {
                @Override
                public void onConnected(Bundle bundle) {
                    guessCurrentPlace();
                }

                @Override
                public void onConnectionSuspended(int i) {

                }
            })
            .addOnConnectionFailedListener(new GoogleApiClient.OnConnectionFailedListener() {
                @Override
                public void onConnectionFailed(ConnectionResult connectionResult) {

                }
            })
            .build();
}


private void guessCurrentPlace() {
    PendingResult<PlaceLikelihoodBuffer> result =
            Places.PlaceDetectionApi.getCurrentPlace(mGoogleApiClient, null);
    result.setResultCallback(new ResultCallback<PlaceLikelihoodBuffer>() {
        @Override
        public void onResult(PlaceLikelihoodBuffer likelyPlaces) {
            if (!likelyPlaces.getStatus().isSuccess()) {
                // Request did not complete successfully
                GooglePlayServicesUtil.getErrorDialog(
                        likelyPlaces.getStatus().getStatusCode(), ServiceProviderActivity.this ,0).show();
                Logger.d(TAG, "Place query did not complete. Error: " + likelyPlaces.getStatus().toString());
                likelyPlaces.release();
                return;
            }
            PlaceLikelihood placeLikelihood = likelyPlaces.get(0);
            String content = "";
            if (placeLikelihood != null && placeLikelihood.getPlace() != null &&
                    !TextUtils.isEmpty(placeLikelihood.getPlace().getName())) {
                content = "Most likely place: " + placeLikelihood.getPlace().getName() + "\n";
            }
            if (placeLikelihood != null) {
                content += "Percent change of being there: " + (int) (placeLikelihood.getLikelihood() * 100) + "%";
            }
            likelyPlaces.release();
        }
    });
}

我总是得到错误,并且 possiblePlaces 的值是: {status=Status{statusCode=INTERNAL_ERROR, resolution=null}, attributions=null}

我将这些添加到我的 AndroidManifest.xml 中

    <meta-data
        android:name="com.google.android.geo.API_KEY"
        android:value="key" />
    <meta-data
        android:name="com.google.android.gms.version"
        android:value="@integer/google_play_services_version" />

<!-- PlacePicker also requires OpenGL ES version 2 -->
<uses-feature
    android:glEsVersion="0x00020000"
    android:required="true" />

和其他需要的使用权限。 有谁知道为什么?

编辑1: 在 Google Developer Console 中,我获取 API 的统计数据,显示所有响应都是“客户端错误 (4XX)”

编辑2: 我的错误,使用发布密钥库生成 KEY 但使用调试密钥库进行调试。 问题解决了。

【问题讨论】:

    标签: android google-places-api


    【解决方案1】:

    我遇到了同样的问题 Place Detection API 返回 INTERNAL_ERROR,我后来发现这是因为 Android 中的新权限。

    我请求了许可并且它有效。我希望它的帮助

    if (ContextCompat.checkSelfPermission(this, Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED) {
         ActivityCompat.requestPermissions( this, new String[] { Android.Manifest.permission.ACCESS_COARSE_LOCATION  }, 2 );
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2016-04-17
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-04-30
      • 1970-01-01
      相关资源
      最近更新 更多