3

FusedLocationProviderApi を使用して、最後の既知の場所を取得したいと考えています。Google のチュートリアルにあるように実行しましたが、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

}
4

1 に答える 1

7

あなたが逃しました

mGoogleApiClient.connect();

于 2015-01-22T23:19:04.663 に答える