android studio无法重载符号LocationClient

时间:2015-02-26 03:56:28

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

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

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

但在我的进口中我有下划线: import 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
    ....

2 个答案:

答案 0 :(得分:2)

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

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

  

弃用的客户端 - 不推荐使用ActivityRecognitionClient LocationClient PlusClient类。如果您在应用中使用这些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

答案 1 :(得分:0)

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

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