无法解析“ com.google.android.gms.location.places.Places”

时间:2018-12-24 12:46:28

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

我正在尝试将google maps与我的android项目一起使用,并且尝试使用Places API来获取用户的位置,但是当我尝试

import com.google.android.gms.location.places.GeoDataClient;
import com.google.android.gms.location.places.Places;
import com.google.android.gms.location.places.PlaceDetectionClient;

在我的项目开始时,我在每个项目上都得到了“不能重新设计符号”,并使用Alt+Enter得到了“ Add library 'Gradle: com.google.android.gms:play-services-places:16.0.0' to classpath”的选项 基本上什么都不做。

在我的build.gradle应用模块文件中

implementation 'com.google.android.gms:play-services-places:16.0.0'

在我的依赖项中,所以我真的不明白是什么问题。

这是我的依赖

dependencies {
implementation project(':feature')
implementation project(':base')
implementation 'com.google.android.gms:play-services-identity:16.0.0'
implementation 'com.android.support.constraint:constraint-layout:1.1.3'
implementation 'com.google.firebase:firebase-ads:17.1.2'
implementation 'com.google.android.gms:play-services-maps:16.0.0'
implementation 'com.google.android.gms:play-services-places:16.0.0'
implementation 'com.google.android.gms:play-services-location:16.0.0'
}

这是我完整的.java文件(我怀疑所有文件都相关,但是无论如何)

package com.example.user.gps_pong.feature;

import android.os.Bundle;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentTransaction;
import android.support.v7.app.AppCompatActivity;
import android.support.v4.app.FragmentActivity;
import com.google.android.gms.maps.CameraUpdateFactory;
import com.google.android.gms.maps.GoogleMap;
import com.google.android.gms.maps.OnMapReadyCallback;
import com.google.android.gms.maps.SupportMapFragment;
import com.google.android.gms.maps.model.LatLng;
import com.google.android.gms.maps.model.MarkerOptions;
import com.google.android.gms.location.places.GeoDataClient;
import com.google.android.gms.location.places.Places;
import com.google.android.gms.location.places.PlaceDetectionClient;

public class ChooseGameMap extends FragmentActivity implements OnMapReadyCallback,android.view.View.OnClickListener {


    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_choose_game_map);
        protected GeoDataClient mGeoDataClient;

        // Construct a GeoDataClient.
        mGeoDataClient = Places.getGeoDataClient(this, null);

        // Construct a PlaceDetectionClient.
        mPlaceDetectionClient = Places.getPlaceDetectionClient(this, null);

        com.google.android.gms.maps.MapFragment mapFragment = (com.google.android.gms.maps.MapFragment) getFragmentManager()
            .findFragmentById(R.id.map);
        mapFragment.getMapAsync(this);

        android.widget.Button btnConfirmSelection = (android.widget.Button) findViewById(R.id.btnConfirmSelection);
        btnConfirmSelection.setOnClickListener(this);
    }
    @Override
    public void onMapReady(GoogleMap map) {
        map.setMapType(GoogleMap.MAP_TYPE_HYBRID);
        map.addMarker(new MarkerOptions()
            .position(new LatLng(0, 0))
            .title("Marker"));
    }
     @Override

    public void onClick(android.view.View v) {
        int i = v.getId();
        if (i == R.id.btnConfirmSelection) {
           android.content.Intent returnIntent = new android.content.Intent();
            returnIntent.putExtra("result","result");
            setResult(android.app.Activity.RESULT_OK,returnIntent);
            finish();
        }
    }

}

(编辑) 这是我完整的应用程序级别Gradel构建:

    apply plugin: 'com.android.application'

android {
    compileSdkVersion 27



    defaultConfig {
        applicationId "com.example.user.gps_pong.app"
        minSdkVersion 24
        targetSdkVersion 27
        versionCode 1
        versionName "1.0"


    }

    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }

}

dependencies {
    implementation project(':feature')
    implementation project(':base')
    implementation 'com.google.android.gms:play-services-identity:16.0.0'
    implementation 'com.android.support.constraint:constraint-layout:1.1.3'
    implementation 'com.google.firebase:firebase-ads:17.1.2'
    implementation 'com.google.android.gms:play-services-maps:16.0.0'
    implementation 'com.google.android.gms:play-services-places:16.0.0'
    implementation 'com.google.android.gms:play-services-location:16.0.0'
}

0 个答案:

没有答案