【问题标题】:Android Studio GeoDataClient cannot be resolvedAndroid Studio GeoDataClient 无法解析
【发布时间】:2018-01-28 10:03:09
【问题描述】:

我在互联网上的任何地方都没有看到这个问题,而且似乎该库没有被弃用,但我无法添加导入:

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

我的 Android SDK 是最新的。

有人知道怎么用吗?或者更确切地说,另一种在 GPS 上获取我当前位置的方法?

非常感谢。

【问题讨论】:

    标签: android api gps location geo


    【解决方案1】:

    尝试添加

    ```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 services api吗?它将使您的项目变大并轻松达到 65k 方法限制
    • 我的意思是我们只需要play-services-places,所以删除play-services-mapsplay-servicesplay-services-location是安全的
    • 我知道这个答案有问题,但我记得jar包含com.google.android.gms.location.places.GeoDataClient;,所以我建议你删除其他jar
    【解决方案2】:

    此链接可以帮助您。它是关于在 android 应用程序中使用地理位置 https://www.toptal.com/android/android-developers-guide-to-google-location-services-api

    【讨论】:

      【解决方案3】:

      @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.xplay-services-places 的最新版本,当前工作版本是15.0.1。 可以在官方文档here查看最新版本

      【讨论】:

        【解决方案4】:

        只需添加:

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

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

        因为 GeoDataClient 是在 11.2.0 中添加的 你可以查看这个官方document

        【讨论】:

        【解决方案5】:

        仅将这一依赖项添加到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"
                }
            }
        }
        

        【讨论】:

          【解决方案6】:

          build.gradle中添加如下依赖

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

          【讨论】:

            猜你喜欢
            • 1970-01-01
            • 2015-11-13
            • 1970-01-01
            • 1970-01-01
            • 1970-01-01
            • 1970-01-01
            • 1970-01-01
            • 1970-01-01
            • 1970-01-01
            相关资源
            最近更新 更多