【发布时间】:2018-01-28 10:03:09
【问题描述】:
我在互联网上的任何地方都没有看到这个问题,而且似乎该库没有被弃用,但我无法添加导入:
import com.google.android.gms.location.places.GeoDataClient;
我的 Android SDK 是最新的。
有人知道怎么用吗?或者更确切地说,另一种在 GPS 上获取我当前位置的方法?
非常感谢。
【问题讨论】:
标签: android api gps location geo
我在互联网上的任何地方都没有看到这个问题,而且似乎该库没有被弃用,但我无法添加导入:
import com.google.android.gms.location.places.GeoDataClient;
我的 Android SDK 是最新的。
有人知道怎么用吗?或者更确切地说,另一种在 GPS 上获取我当前位置的方法?
非常感谢。
【问题讨论】:
标签: android api gps location geo
尝试添加
```gradle
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是安全的
jar包含com.google.android.gms.location.places.GeoDataClient;,所以我建议你删除其他jar。
此链接可以帮助您。它是关于在 android 应用程序中使用地理位置 https://www.toptal.com/android/android-developers-guide-to-google-location-services-api
【讨论】:
@Xianwei 的回答是有效的,但是随着时间的推移不断改进我们的代码是好的,因为总会有一个新的、更好的和更简单的实现。基本上是@Xianwei's answer的更多细节和改进。
在您的顶级 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/'
}
}
在您的应用级中添加places google play service依赖项build.gradle
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。
可以在官方文档here查看最新版本
【讨论】:
只需添加:
compile 'com.google.android.gms:play-services-places:11.2.0'
和
repositories {
jcenter()
maven {
url "https://maven.google.com"
}
}
因为 GeoDataClient 是在 11.2.0 中添加的 你可以查看这个官方document
【讨论】:
仅将这一依赖项添加到apps build.gradle
compile 'com.google.android.gms:play-services:11.8.0'
project's以下代码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'
【讨论】: