无法将Google Places PlacePicker导入Android项目

15

我试图编写一个简单的程序,其中涉及使用PlacePicker来捕获位置信息。然而,我的项目似乎无法解析必要的导入。

build.gradle

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    testCompile 'junit:junit:4.12'
    compile 'com.android.support:appcompat-v7:23.3.0'
    compile 'com.google.android.gms:play-services-location:9.2.0'
    compile 'com.google.android.gms:play-services-maps:9.2.0'
}

活动:

import com.google.android.gms.location.places.Place; // "Place" is not resolved
import com.google.android.gms.location.places.ui.PlacePicker; // "ui" is not resolved
import com.google.android.gms.maps.model.LatLng;

LatLng 的导入似乎可以正常工作,但其他两个不能。当我导入完整的 com.google.android.gms:play-services:9.2.0 API 时,整个项目都能够正常运行,但我希望使用特定的 API 调用来减少不必要的库。


“整个项目运行良好”是什么意思?你不是已经导入了完整的地图包吗? - OneCricketeer
@cricket_007 - 看起来我的初始问题有误。我的意思是说,只有在我导入完整的Google play-services包(即地图、位置、身份验证、身份识别、健身等)时才能正常工作,这是我不需要的大量库。我会编辑问题。 - Fawfulcopter
1个回答

67
在play-services 9.2.0中,places API不再位于location中。它们现在在自己的places依赖项中。为了解决这些问题,您应该将以下内容添加到build.gradle中:
implementation 'com.google.android.gms:play-services-places:9.2.0'
答案在这里已经被回答:here

太棒了。谢谢。 - Farruh Habibullaev
这个问题花费的时间太长了。我仍然很好奇,在Google Places API“入门”页面上是否有提到这一点? - Bimde

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接