代码之家  ›  专栏  ›  技术社区  ›  Naveen Kumar M

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

  •  2
  • Naveen Kumar M  · 技术社区  · 9 年前

    在里面 '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 回复  |  直到 9 年前
        1
  •  8
  •   Daniel Nugent    9 年前

    location places 为了编译问题中的代码:

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