我从http://developer.android.com/training/location/retrieve-current.html下载了一个演示项目,我想我没有丢失任何步骤;但我找不到哪个jar文件包含“com.google.android.gms.location.LocationClient.class”文件
我们找到了所有“google-play-services.jar”和“maps.jar”以及“android.jar(所有版本)” 不包含“LocationClient.class”?
答案 0 :(得分:25)
添加到Gradle文件(x.y.z - Google Play服务的实际版本):
compile 'com.google.android.gms:play-services-location:x.y.z'
答案 1 :(得分:14)
上一次GPS lib存在一些问题。您必须使用比最新版本(6. +)更旧的版本。尝试使用旧版本。我没有看到关于LocationClient.class
的文档中有任何内容被弃用或遗漏。
compile 'com.google.android.gms:play-services:5.+'
答案 2 :(得分:13)
不推荐使用LocationClient。您必须使用GoogleApiclient
,如下所示:
1:声明GoogleApiClient变量
private GoogleApiClient mGoogleApiClient;
2:实例化
mGoogleApiClient = new GoogleApiClient.Builder(mThisActivity)
.addApi(LocationServices.API)
.addConnectionCallbacks(this)
.addOnConnectionFailedListener(this)
.build();
3:实施回调
public class YourClass extends BaseFragment implements
GoogleApiClient.ConnectionCallbacks,
GoogleApiClient.OnConnectionFailedListener, LocationListener {
@Override
public void onConnectionFailed(ConnectionResult result) {
// your code goes here
}
@Override
public void onConnected(Bundle connectionHint) {
//your code goes here
}
@Override
public void onConnectionSuspended(int cause) {
//your code goes here
}
}
4:开始获取位置更新:
LocationServices.FusedLocationApi.requestLocationUpdates(
mGoogleApiClient, mLocationRequest, this);
5:删除位置更新:
LocationServices.FusedLocationApi.removeLocationUpdates(mGoogleApiClient, this);
6:获取最后一个位置:
private Location mCurrentLocation;
mCurrentLocation = LocationServices.FusedLocationApi.getLastLocation(mGoogleApiClient);
答案 3 :(得分:3)
由于不推荐使用位置客户端,因此不再在包中找到该类。我们必须使用以下代码
mGoogleApiClient = new GoogleApiClient.Builder(this)
.addApi(LocationServices.API)
.addConnectionCallbacks(new GoogleApiClient.ConnectionCallbacks(){
@Override
public void onConnected(Bundle arg0) {
// TODO Auto-generated method stub
LocationRequest request = new LocationRequest();
int priority = LocationRequest.PRIORITY_BALANCED_POWER_ACCURACY;
if (enableHighAccuracy) {
priority = LocationRequest.PRIORITY_HIGH_ACCURACY;
}
request.setPriority(priority);
LocationServices.FusedLocationApi.requestLocationUpdates(
locationClient, request, new LocationListener() {
@Override
public void onLocationChanged(Location location) {
locationClient.disconnect();
}
});
}
@Override
public void onConnectionSuspended(int arg0) {
// TODO Auto-generated method stub
}
})
.addOnConnectionFailedListener(new GoogleApiClient.OnConnectionFailedListener() {
@Override
public void onConnectionFailed(ConnectionResult arg0) {
// TODO Auto-generated method stub
}
})
.build();
答案 4 :(得分:2)
Jeremie Petitjean的解决方案对我有用。进入youbuild.grade
文件并配置您的应用程序以获得较低版本。这是我使用的,它现在有效:
apply plugin: 'com.android.application'
android {
compileSdkVersion 19
buildToolsVersion "19.1.0"
defaultConfig {
applicationId "<APPLICATION NAME>"
minSdkVersion 9
targetSdkVersion 19
versionCode 1
versionName "1.0"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.android.support:support-v4:19.1.0'
compile 'com.android.support:appcompat-v7:19.0.1'
compile 'com.google.android.gms:play-services:4.2+'
}
答案 5 :(得分:1)
您需要更新Google Play Service SDK,然后使用更新的库。
答案 6 :(得分:1)
为了直接使用Phonegap CLI工作的任何人的利益。在plugin.xml中,您需要行
Base
答案 7 :(得分:1)
如果您使用Android Studio,请尝试此操作:
右键点击您的应用文件夹 - &gt;打开模块设置 - &gt;依赖关系 - &gt;点击加号按钮 - &gt;选择库依赖 - &gt;搜索&#34;播放服务&#34; - &GT;双击com.google.android.gms:play-services
按确定并等待Gradle重建。如果发生错误,请清理并重建项目。 here
答案 8 :(得分:0)
使用Android SDK Manager将Google Play库更新为最新版本。另外,我必须手动删除库并将其再次添加到these steps之后的项目中。版本3.1.36包含:
位置文件夹:
您可能还需要更新ADT / SDK。
答案 9 :(得分:0)
检查以下链接
The import com.google.android.gms cannot be resolved
How to add google-play-services.jar project dependency so my project will run and present map
按照以下步骤节省您的时间
通过这种方式,您可以导入Google Play服务库。 如果您对此有任何疑问,请与我们联系。
答案 10 :(得分:0)
将此添加到您的项目中
implementation 'com.google.android.gms:play-services-location:16.0.0'//location services`