1

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

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

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

有任何想法吗?

我的代码如下:

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

构建.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
    ....
4

2 回答 2

2

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

事实上,LocationClient该类已被弃用。来自Google Play 服务 | 安卓开发者

不推荐使用的客户端 -不推荐使用ActivityRecognitionClientLocationClientPlusClient类。如果您在应用程序中使用了这些 API,并且想要调用 Google Play 服务 6.5 或更高版本的 API,则必须切换到使用GoogleApiClient. 有关使用的更多信息GoogleApiClient,请参阅访问 Google API

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

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

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

于 2015-02-26T04:00:01.730 回答
0

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

compile 'com.google.android.gms:play-services:5.0.89'
于 2017-01-31T06:31:59.073 回答