Android Studio无法解析com.google.android.gms.location.places.AutocompleteFilter

Bug*_*der 21 android google-places-api google-play-services android-studio

我试图在本文后面实现自动完成位置搜索.

http://www.truiton.com/2015/04/android-places-api-autocomplete-getplacebyid/

我已经遵循了所有步骤,并在build.gradle文件中添加了适当的依赖项.

dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.android.support:appcompat-v7:21.0.3'
compile 'com.google.android.gms:play-services:6.5.87'
}
Run Code Online (Sandbox Code Playgroud)

此处还有我的清单中的元数据部分.

    <meta-data
        android:name="com.google.android.gms.version"
        android:value="@integer/google_play_services_version" />
    <meta-data
        android:name="com.google.android.maps.v2.API_KEY"
        android:value="@string/google_maps_key" />
Run Code Online (Sandbox Code Playgroud)

我也安装了所有必需的SDK组件.仍然我的android工作室无法解析以下导入中的places部分:

import com.google.android.gms.location.places.AutocompleteFilter;
import com.google.android.gms.location.places.AutocompletePrediction;
import com.google.android.gms.location.places.AutocompletePredictionBuffer;
import com.google.android.gms.location.places.Places;
Run Code Online (Sandbox Code Playgroud)

这是他们看起来的样子,因为他们找不到Places部分.

在此输入图像描述

我该如何解决这个问题?我正在为我的应用程序使用SDK 19.

Ujj*_*ngh 48

添加compile 'com.google.android.gms:play-services-places:<version>,<version>至少9.2.1在哪里:dependencies在你的模块中build.gradle

  • 谢谢!对于较新版本的Play服务,这是必须的,因为Google Places API不再位于"位置"捆绑包上. (9认同)
  • 这应该是新接受的答案.Places API不再位于位置! (2认同)

vis*_*hwa 26

在play-services 9.2.0中,places API不再位于位置.那些现在在他们自己的地方依赖.要解决这些问题,您应该将其添加到build.gradle中.

编译'com.google.android.gms:play-services-places:9.2.0'

查看

Places类从Android播放服务9.2.0中删除


ian*_*ake 14

Places API仅在Google Play服务7.0中添加:您需要至少更新您的依赖关系7.0.0,尽管此答案的最新版本是15.0.0.

请注意,几乎所有情况下,您都应该使用选择性API来仅包含您需要的Google Play服务部分.在这种情况下,您实际上使用了依赖项,例如

implementation 'com.google.android.gms:play-services-location:15.0.0'
Run Code Online (Sandbox Code Playgroud)


Yuv*_*uvi 8

自Play Services 9.2版起,我们应添加以下依赖性来访问Google Places API.

 compile 'com.google.android.gms:play-services-places:11.0.2'
Run Code Online (Sandbox Code Playgroud)

撰写本文时的最新版本.

这个帖子的接受答案已经过时了.


Jen*_*dra 7

build.gradle(Module:app)中添加以下两个依赖项

implementation  'com.google.android.gms:play-services-location:15.0.1'
implementation 'com.google.android.gms:play-services-places:15.0.1'
Run Code Online (Sandbox Code Playgroud)


小智 5

尝试包括编译'com.google.android.gms:play-services-places:10.2.0'