gpt4 book ai didi

android - GoogleApiClient 无法连接

转载 作者:太空宇宙 更新时间:2023-11-03 12:17:58 25 4
gpt4 key购买 nike

我想使用 FusedLocationProviderApi 获取最后的已知位置。我按照谷歌教程所说的那样做了,但似乎 GoogleApiClient 没有连接,至少它没有触发 onConnected 或 onConnectionFailed 方法。我希望你能帮助我,提前致谢。

import com.example.stoos.data.DataModelOrt;
import com.google.android.gms.common.ConnectionResult;
import com.google.android.gms.common.GooglePlayServicesNotAvailableException;
import com.google.android.gms.common.GooglePlayServicesUtil;
import com.google.android.gms.common.api.GoogleApiClient;
import com.google.android.gms.common.api.GoogleApiClient.ConnectionCallbacks;
import com.google.android.gms.common.api.GoogleApiClient.OnConnectionFailedListener;
import com.google.android.gms.location.LocationServices;
import com.google.android.gms.maps.CameraUpdateFactory;
import com.google.android.gms.maps.GoogleMap;
import com.google.android.gms.maps.GoogleMap.InfoWindowAdapter;
import com.google.android.gms.maps.GoogleMap.OnInfoWindowClickListener;
import com.google.android.gms.maps.GoogleMap.OnMapLoadedCallback;
import com.google.android.gms.maps.GoogleMap.OnMarkerClickListener;
import com.google.android.gms.maps.MapView;
import com.google.android.gms.maps.MapsInitializer;
import com.google.android.gms.maps.model.BitmapDescriptorFactory;
import com.google.android.gms.maps.model.LatLng;
import com.google.android.gms.maps.model.Marker;
import com.google.android.gms.maps.model.MarkerOptions;
.
.
.
public class OrtHinzufugen extends Activity implements
ConnectionCallbacks, OnConnectionFailedListener{
.
.
.
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.ort_auswahlen);
getActionBar().setDisplayHomeAsUpEnabled(true);

buildGoogleApiClient();
.
.
.
}
protected synchronized void buildGoogleApiClient() {
mGoogleApiClient = new GoogleApiClient.Builder(this)
.addConnectionCallbacks(this)
.addOnConnectionFailedListener(this)
.addApi(LocationServices.API)
.build();
}
.
.
.
@Override
public void onConnectionFailed(ConnectionResult arg0) {
System.out.println("Failed");

}

@Override
public void onConnected(Bundle connectionHint) {
System.out.println("check1?");
Location mLastLocation;
mLastLocation = LocationServices.FusedLocationApi.getLastLocation(
mGoogleApiClient);
if (mLastLocation != null) {
if(mLastLocation.getAccuracy() > 100){
Toast.makeText(getApplicationContext(), "Für bessere Ergebnisse GPS anmachen", Toast.LENGTH_LONG).show();
}
Intent ServiceIntent = new Intent(getApplicationContext(),
SendeAnfrageService.class);
ServiceIntent.putExtra("LATITUDE", mLastLocation.getLatitude());
ServiceIntent.putExtra("LONGITUDE", mLastLocation.getLongitude());
startService(ServiceIntent);
System.out.println("check2?");
}else{
Toast.makeText(getApplicationContext(), "Probleme beim laden der Orte. Versuche es bitte nocheinmal", Toast.LENGTH_LONG).show();
}

}

@Override
public void onConnectionSuspended(int arg0) {
// TODO Auto-generated method stub

}

最佳答案

你错过了

mGoogleApiClient.connect();

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

25 4 0
文章推荐: android - match_parent 不适用于 SherlockFragment 中 listView 的 layout_height
文章推荐: php - mysqli 从数据库中获取信息
文章推荐: php - 如何将数据库表中的 SQL 数据回显到