2016-11-29 20 views
0

我是GeoFencing的新手,我正在尝试将API添加到GoogleApiClient实例。但它显示错误,如找不到变量LocationServices。 这里是我的代码:在GoogleApiClient实例中找不到符号变量“LocationServices”?

private void createGoogleApi() { 
    Log.d(TAG, "createGoogleApi()"); 
    if (googleApiClient == null) { 
     googleApiClient = new GoogleApiClient.Builder(this) 
       .addConnectionCallbacks(this) 
       .addOnConnectionFailedListener(this) 
       .addApi(LocationServices.API) 
       .build(); 
    } 
} 

而且我是gradle这个

compile 'com.google.android.gms:play-services-maps:9.8.0' 

清单文件

<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/> 
<uses-permission android:name="android.permission.INTERNET" /> 
<meta-data 
     android:name="com.google.android.geo.API_KEY" 
     android:value="Server_key" /> 

你能请看看this.or否则你可以提供一些其他文档或链接供参考。谢谢

+0

检查这可能有所帮助:http://stackoverflow.com/a/40782046/5241603 –

回答

0

在gradle add play-services location

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

一旦您检查完所有更新都在SDK中完成。

0

我想你错过了这样的事情:

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

进一步参考see here

0

你只需要添加下面一行在你的应用程序级的build.gradle文件

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