简体   繁体   English

在Android Studio上设置位置服务

[英]Setting up location services on Android studio

I am trying to set up Location services in an app according to instructions of developer.android.com . 我正在尝试根据developer.android.com的说明在应用程序中设置位置服务 I have inserted the following code into the onCreate method 我已经将以下代码插入到onCreate方法中

// Create an instance of GoogleAPIClient.
        if (mGoogleApiClient == null) {
            mGoogleApiClient = new GoogleApiClient.Builder(this)
                    .addConnectionCallbacks(this)
                    .addOnConnectionFailedListener(this)
                    .addApi(LocationServices.API)
                    .build();
        }

The class names GoogleApiClient and LocationServices appear in red and "Cannot resolve Symbol" appears on the tooltip. 类名称GoogleApiClientLocationServices以红色显示,工具提示上显示“无法解析符号” I have tried 我努力了

  • Rebuilding Project 重建项目
  • Cleaning Project 清洁项目
  • Invalidate Caches/Restart 无效的缓存/重启
  • using an import from developer.android.com 使用来自developer.android.com的导入

import com.google.android.gms.common.api.GoogleApiClient; 导入com.google.android.gms.common.api.GoogleApiClient;

but to no avail. 但无济于事。 Will anyone please advise me? 谁能告诉我吗? :) :)

Have You Declared this? 你宣布了​​吗?

     private GoogleApiClient mGoogleApiClient;

and add this to your gradle file, and then sync. 并将其添加到您的gradle文件中,然后进行同步。

then clean and build. 然后清理并建造。

    apply plugin: 'com.android.application'
...

dependencies {
    compile 'com.google.android.gms:play-services:9.2.1'
}

Have a look at below link, 看看下面的链接,

https://developers.google.com/android/guides/setup https://developers.google.com/android/guides/setup

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM