MapActivity android studio

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了MapActivity android studio相关的知识,希望对你有一定的参考价值。

我的程序有问题。我实现了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);

当我更新build griadle时,GEO_DATA_API,PLACE_DETECTION_API,GeoDataApi不起作用,对于此实现'com.google.android.libraries.places:places: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.
    
  

以上是关于MapActivity android studio的主要内容,如果未能解决你的问题,请参考以下文章

带有 10 个标记的 Android 基本 API v2 MapActivity outOfMemory

如何向 MapActivity 添加菜单?

从 Firebase 检索位置数据未进入 MapActivity

将 MapActivity (FragmentActivity) 添加到 Navigation Drawers (Fragment)

Android Study Notes

android study day2