在com.google.android.gms中:play-services-location:9.4.0'无法导入导入com.google.android.gms.location.places.Places

时间:2016-08-26 07:11:33

标签: android google-play-services google-places-api google-api-client

'com.google.android.gms:play-services-location:9.4.0'

无法导入导入 com.google.android.gms.location.places.Places 由于此无法构建GoogleApiClient而且无法使用Places.GeoDataApi.getPlaceById.

但在'com.google.android.gms:play-services-location:8.4.0'我们可以正确使用它。

mGoogleApiClient = new GoogleApiClient
                .Builder(this)
                .addApi(Places.GEO_DATA_API)
                .addApi(Places.PLACE_DETECTION_API)
                .enableAutoManage(this, this)
                .build();

Places.GeoDataApi.getPlaceById(mGoogleApiClient, placeId).setResultCallback(new ResultCallback<PlaceBuffer>() {
            @Override
            public void onResult(PlaceBuffer places) {
                if (places.getStatus().isSuccess() && places.getCount() > 0) {
                    final com.google.android.gms.location.places.Place myPlace = places.get(0);
                    Log.i(TAG, "Place found: " + myPlace.getName());
                    map.addMarker(new MarkerOptions()
                            .position(myPlace.getLatLng())
                            .title(myPlace.getName().toString())
                            .snippet(myPlace.getAddress().toString()));
                    map.moveCamera(CameraUpdateFactory.newLatLng(myPlace.getLatLng()));
                }
                places.release();
            }
        });

1 个答案:

答案 0 :(得分:8)

在最新版本的Google Play服务中,他们已经进一步细分了,现在您需要同时包含locationplaces,以便编译问题中的代码:< / p>

dependencies {
    compile 'com.google.android.gms:play-services-location:9.4.0'
    compile 'com.google.android.gms:play-services-places:9.4.0'
    //.......
}