在'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();
}
});
答案 0 :(得分:8)
在最新版本的Google Play服务中,他们已经进一步细分了,现在您需要同时包含location
和places
,以便编译问题中的代码:< / p>
dependencies {
compile 'com.google.android.gms:play-services-location:9.4.0'
compile 'com.google.android.gms:play-services-places:9.4.0'
//.......
}