Android Studio中GeoDataClient无法解析。

10

我在互联网上没有看到这个问题,而且这个库似乎也没有过时,但我就是无法添加导入:

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

我的Android SDK已经更新。

有人知道怎么使用它吗?还是说,有其他方法可以获取我的GPS当前位置吗?

非常感谢。

6个回答

12

只需要添加:

compile 'com.google.android.gms:play-services-places:11.2.0'

repositories {
    jcenter()
    maven {
        url "https://maven.google.com"
    }
}

因为在11.2.0版本中添加了GeoDataClient,您可以查看官方 文档


对于Gradle的最新版本,高于4.1。您可以使用我的答案,链接为https://dev59.com/UFcO5IYBdhLWcg3wchUC#46371963 - HendraWD

6
尝试添加
```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"
    }
}

为结束标签。

```

表示代码块的起始和结束标记。
最后,进行构建->重新构建项目

你难道不是一次性导入了所有的Google Play服务API吗?这会使你的项目变得庞大,并很容易达到65k方法限制。 - HendraWD
我的意思是我们只需要 play-services-places,所以安全起见可以删除 play-services-mapsplay-servicesplay-services-location - HendraWD
我知道这个答案有一些问题,但是我记不清哪个jar包含了com.google.android.gms.location.places.GeoDataClient;,所以我建议你删除其他的jar - jiar wang

1

只需将这个依赖项添加到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"
        }
    }
}

0
请在 build.gradle 中添加以下依赖项:

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


0

0
@Xianwei的答案是有效的,但随着时间的推移,不断改进我们的代码是很好的,因为总会有新的、更好的和更简单的实现方式。基本上,这是对@Xianwei答案的更详细和改进。
在您的顶层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/'
    }
}   

在你的应用程序级别build.gradle中添加Google Play服务依赖项。具体做法是添加 places google play service 依赖项。
dependencies {
    implementation fileTree(include: ['*.jar'], dir: 'libs')
    // Your other dependencies...
    implementation 'com.google.android.gms:play-services-places:x.x.x'
}

其中x.x.xplay-services-places的最新版本,当前工作版本为15.0.1。 您可以在官方文档此处中检查最新版本。


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