MapActivity Android Studio

时间:2019-02-23 09:10:44

标签: android

我的程序有问题。我实现了https://developers.google.com/places/android-sdk/start,并且我的代码有问题。

我的构建gradle

dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'com.android.support:appcompat-v7:28.0.0'
implementation 'com.android.support:design:28.0.0'
implementation 'com.android.support.constraint:constraint-layout:1.1.3'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'com.android.support.test:runner:1.0.2'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'

// Google play services

implementation 'com.google.android.libraries.places:places:1.0.0'

在ma代码中,我无权访问res文件,也不知道如何解决该问题,并且

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


PendingResult<PlaceBuffer> placeResult = Places.GeoDataApi
                .getPlaceById(mGoogleApiClient, placeId);
        placeResult.setResultCallback(mUpdatePlaceDetailsCallback);

当我更新构建标准时,GEO_DATA_API,PLACE_DETECTION_API,GeoDataApi不起作用,对于此实现'com.google.android.libraries.places:places:1.0.0'

1 个答案:

答案 0 :(得分:0)

尝试以下

在Oncreate()中初始化以下代码;

// Add an import statement for the client library.
import com.google.android.libraries.places.api.Places;

// Initialize Places.
Places.initialize(getApplicationContext(), "***YOUR API KEY***");
// Create a new Places client instance. PlacesClient placesClient = 
Places.createClient(this);

新的PlacesAPI已初始化。.

对于“自动填充”场所,请使用以下代码(您也可以使用“自动填充片段”)

// Set the fields to specify which types of place data to return.
List<Place.Field> fields = Arrays.asList(Place.Field.ID, Place.Field.NAME);
// Start the autocomplete intent.
Intent intent = new Autocomplete.IntentBuilder(
    AutocompleteActivityMode.FULLSCREEN, fields)
    .build(this);
startActivityForResult(intent, AUTOCOMPLETE_REQUEST_CODE);

@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
if (requestCode == AUTOCOMPLETE_REQUEST_CODE) {
    if (resultCode == RESULT_OK) {
        Place place = Autocomplete.getPlaceFromIntent(data);
        Log.i(TAG, "Place: " + place.getName() + ", " + place.getId());
    } else if (resultCode == AutocompleteActivity.RESULT_ERROR) {
        // TODO: Handle the error.
        Status status = Autocomplete.getStatusFromIntent(data);
        Log.i(TAG, status.getStatusMessage());
    } else if (resultCode == RESULT_CANCELED) {
        // The user canceled the operation.
    }
  }
}