我在互联网上没有看到这个问题,而且这个库似乎也没有过时,但我就是无法添加导入:
import com.google.android.gms.location.places.GeoDataClient;
我的Android SDK已经更新。
有人知道怎么使用它吗?还是说,有其他方法可以获取我的GPS当前位置吗?
非常感谢。
只需要添加:
compile 'com.google.android.gms:play-services-places:11.2.0'
和
repositories {
jcenter()
maven {
url "https://maven.google.com"
}
}
因为在11.2.0版本中添加了GeoDataClient,您可以查看官方 文档。
compile 'com.google.android.gms:play-services-maps:11.2.0'
compile 'com.google.android.gms:play-services-places:11.2.0'
compile 'com.google.android.gms:play-services:11.2.0'
compile 'com.google.android.gms:play-services-location:11.2.0'
build.gradle
文件中使用了```gradle```,那么你可能需要添加一些内容。请按照格式要求进行修改。allprojects {
repositories {
jcenter()
maven {
url "https://maven.google.com"
}
}
为结束标签。
```
表示代码块的起始和结束标记。play-services-places
,所以安全起见可以删除 play-services-maps
、play-services
和 play-services-location
。 - HendraWDjar
包含了com.google.android.gms.location.places.GeoDataClient;
,所以我建议你删除其他的jar
。 - jiar wang只需将这个依赖项添加到apps
build.gradle文件中即可
compile 'com.google.android.gms:play-services:11.8.0'
在项目的 build.gradle
文件中添加以下代码应该可以工作。
allprojects {
repositories {
google()
jcenter()
maven {
url "https://maven.google.com"
}
}
}
build.gradle
中添加以下依赖项:
implementation 'com.google.android.gms:play-services-places:15.0.1'
这个链接可以帮助你。它是关于在Android应用程序中使用地理位置的。 https://www.toptal.com/android/android-developers-guide-to-google-location-services-api
build.gradle
中添加google()
存储库。allprojects {
repositories {
jcenter()
google()
// If you're using a version of Gradle lower than 4.1, you must instead use:
// maven {
// url 'https://maven.google.com'
// }
// An alternative URL is 'https://dl.google.com/dl/android/maven2/'
}
}
dependencies {
implementation fileTree(include: ['*.jar'], dir: 'libs')
// Your other dependencies...
implementation 'com.google.android.gms:play-services-places:x.x.x'
}
其中x.x.x是play-services-places
的最新版本,当前工作版本为15.0.1。
您可以在官方文档此处中检查最新版本。