【问题标题】:Google Places API not returning Place Details outputGoogle Places API 不返回 Place Details 输出
【发布时间】:2015-07-06 23:42:39
【问题描述】:

我使用下面给定的代码(取自here)来获取给定placeIdPlaceDetails,但Google Places API 不断返回以下状态。

状态:

Status{statusCode=unknown status code: 9000, resolution=null}

GoogleApiClient 已连接。 Google Developer Console 还显示,例如收到了 2 个请求,并报告了 2 个错误。

我使用此link 获得了给定位置的placeId

代码:

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        // setContentView(R.layout.activity_main);

        mGoogleApiClient = new GoogleApiClient
                .Builder(this)
                        .addApi(Places.GEO_DATA_API)
                        .addApi(Places.PLACE_DETECTION_API)
                        .addConnectionCallbacks(this)
                        .addOnConnectionFailedListener(this)
                        .build();

   }

    @Override
    public void onStart() {
        super.onStart();
        mGoogleApiClient.connect();
    }

    @Override
    public void onConnected(Bundle connectionHint) {
        // TODO Auto-generated method stub
        if (GooglePlayServicesUtil.isGooglePlayServicesAvailable(this) == ConnectionResult.SUCCESS)
        {
            Log.e("HELLOPPPPPPPPP", "GOOOOOGLE API Connected:  df ");
            Places.GeoDataApi.getPlaceById(mGoogleApiClient, placeID)
                    .setResultCallback(new ResultCallback<PlaceBuffer>() {
                        @Override
                        public void onResult(PlaceBuffer places) {
                            Log.e("HELLOPPPPPPPPP",
                                    "onResult is invoked at least: status = " + places.getStatus()
                                            + ", count = " + places.getCount());
                            if (places.getStatus().isSuccess()) {
                                final Place myPlace = places.get(0);
                                Log.e("HELLOPPPPPPPPP", "Place f    ound: " + myPlace.getName());
                            }
                            places.release();
                        }
                    });

        }
        else
        {
            Log.e("HELLOPPPPPPPPP", "NOTTTTTTTTT GOOOOOGLE API      Connected:  df ");
        }
    }

相关清单项:

<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="com.google.android.providers.gsf.permission.READ_GSERVICES" />

<application
    android:allowBackup="true"
    android:icon="@drawable/ic_launcher"
    android:label="@string/app_name" >
    <meta-data
        android:name="com.google.android.gms.version"
        android:value="@integer/google_play_services_version" />
    <meta-data
        android:name="com.google.android.geo.API_KEY"
        android:value="<MyKey>" />

</application>

Google 开发者控制台设置:

我在控制台设置中启用了“Android 版 Google Places API”和“Google Maps Geolocation API”。我正在为我的应用程序使用 Android Key。

【问题讨论】:

  • 你能解释一下你到底想要什么吗?

标签: android google-places-api google-geocoding-api


【解决方案1】:

这是我用来查询地点详情的一种方法。 Alias 是具有 google place id 的自定义模型

void queryPlaceDetails(final Alias alias) {

    showProgressDialog("Getting place details");

    PendingResult<PlaceBuffer> placeResult = Places.GeoDataApi.getPlaceById(googleApiClient, alias.getPlaceId());

    placeResult.setResultCallback(new ResultCallback<PlaceBuffer>() {
        @Override
        public void onResult(PlaceBuffer places) {

            hideProgressDialog();

            ..do stuff here with results
        }
    });
}

仔细检查您的密钥哈希是否正确

【讨论】:

    猜你喜欢
    • 2019-12-27
    • 2017-07-07
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-09-07
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多