gpt4 book ai didi

java - GoogleApiClient 无法在 android studio 中连接

转载 作者:行者123 更新时间:2023-12-02 10:50:28 25 4
gpt4 key购买 nike

我有一段时间无法连接谷歌地图 Api 客户端。即使对象返回不为空,但仍然无法连接。我还在 list 中提到了权限

下面是我的代码

 public void onMapReady(GoogleMap googleMap) {
mMap = googleMap;
buildGoogleApiClient();
}

protected synchronized void buildGoogleApiClient(){
googleApiClient = new GoogleApiClient.Builder(getBaseContext())
.addConnectionCallbacks(this)
.addOnConnectionFailedListener(this)
.addApi(LocationServices.API)
.build();
googleApiClient.connect();
}
@Override
public void onConnected(@Nullable Bundle bundle) {
mLocationRequest = new LocationRequest();
mLocationRequest.setInterval(1000);
mLocationRequest.setFastestInterval(1000);
mLocationRequest.setPriority(mLocationRequest.PRIORITY_HIGH_ACCURACY);

if (ActivityCompat.checkSelfPermission(this, Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED && ActivityCompat.checkSelfPermission(this, Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED) {

return;
}
//

LocationServices.getFusedLocationProviderClient(this).requestLocationUpdates(mLocationRequest,new LocationCallback());
LocationServices.FusedLocationApi.requestLocationUpdates(googleApiClient, mLocationRequest, (com.google.android.gms.location.LocationListener) this);
}

我的 gradle 依赖项如下所示

 dependencies {
implementation fileTree(include: ['*.jar'], dir: 'libs')
implementation 'com.android.support:appcompat-v7:26.1.0'
implementation 'com.google.android.gms:play-services-maps:15.0.1'
implementation 'com.google.android.gms:play-services-vision:15.0.2'
implementation 'com.google.android.gms:play-services-location:15.0.1'
implementation 'com.google.android.gms:play-services-maps:15.0.1'

implementation 'com.google.firebase:firebase-core:16.0.1'
implementation 'com.google.firebase:firebase-database:16.0.1'
implementation 'com.android.support:design:26.1.0'
implementation 'com.android.support.constraint:constraint-layout:1.1.2'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'com.android.support.test:runner:1.0.2'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
}
apply plugin: 'com.google.gms.google-services'

我是谷歌地图项目的新手,对此知之甚少。如果有人有解决方案,请帮助我。提前致谢

最佳答案

我通过在我使用的公共(public)类中实现 GoogleApiClient.OnConnectionFailedListener 解决了这个问题。您可能还没有这样做,这是连接到 API 所必需的。

关于java - GoogleApiClient 无法在 android studio 中连接,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52222174/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com