【问题标题】:android studio cannot resilve symbol LocationClientandroid studio 无法解析符号 LocationClient
【发布时间】:2015-02-26 03:56:28
【问题描述】:

我正在使用 AndroidStudio 并尝试使用 googleplayservices 进行地理编码。

我遵循了 android 教程: http://developer.android.com/google/play-services/setup.html

但在我的导入中,我有下划线: 导入 android.location.LocationClient; 上面写着:无法解析符号位置客户端

有什么想法吗?

我的代码如下:

//imports
...
import android.location.Location;
import com.google.android.gms.location.LocationClient;
import android.location.LocationClient;
...

build.grandle

...
dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    compile 'com.android.support:appcompat-v7:21.0.3'
    compile files('libs/android-async-http-1.4.6.jar')
    compile 'com.google.android.gms:play-services:6.5.87'
}
...

最后是我的 xml 清单:

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.example.name.application_name" >
    <uses-permission android:name="android.permission.INTERNET" />
    <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>
    <uses-permission android:name="android.permission.ACCESS_LOCATION_EXTRA_COMMANDS"/>
    <uses-permission android:name="android.permission.READ_LOGS"/>
    ....
        <application
            android:allowBackup="true"
            android:icon="@drawable/ic_launcher"
            android:label="@string/app_name"
            android:theme="@style/AppTheme" >
            <meta-data
                android:name="com.google.android.gms.version"
                android:value="@integer/google_play_services_version" />
            <activity
    ....

【问题讨论】:

    标签: android android-studio google-play-services location-client


    【解决方案1】:

    android.location 中没有LocationClient。这就是您的导入导致错误的原因。

    事实上,LocationClient 类已被弃用。来自Google Play Services | Android Developers

    已弃用的客户端 - ActivityRecognitionClientLocationClientPlusClient 类已弃用。如果您在应用程序中使用了这些 API,并且想要调用 Google Play 服务 6.5 或更高版本的 API,则必须切换到利用 GoogleApiClient 的新编程模型。有关使用GoogleApiClient 的更多信息,请参阅Accessing Google APIs

    使用这些 API 代替已弃用的 API:

    ...如果您之前使用的是 LocationClient,请改为调用 com.google.android.gms.location 包中的 API。

    有关从LocationClient 迁移到GoogleApiClient 的快速信息,请参阅android - LocationClient class not found on google play services rev 22

    【讨论】:

    • 谢谢,我不知道LocationClient 已被弃用......我会阅读更多关于......
    【解决方案2】:

    在您的 build.gradle 中添加 google play services 旧版本:

    compile 'com.google.android.gms:play-services:5.0.89'
    

    【讨论】:

      猜你喜欢
      • 2015-05-14
      • 2018-05-03
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-11-15
      • 1970-01-01
      • 2015-12-17
      相关资源
      最近更新 更多