Android - Kann den Breiten- / Längengradwert nicht abrufen, um die Variable @ zu speichern und weiterzuleite

Ich versuche, den Breiten- / Längengrad in den Variablen x3 und x4 zu speichern, um das Spot [] -Array weiterzuleiten, aber es wird 0 zurückgegeben. Ich habe versucht, es mit der onConnected-Methode zu drucken, und es funktioniert einwandfrei.

Ich habe auch andere Methoden ausprobiert, um Marker auf Google Map hinzuzufügen, und ich habe map.addMarker stattdessen auf die onConnected-Methode gesetzt, aber meine App wird geschlossen. Wenn Sie vorschlagen können, wo Sie addMarker platzieren möchten, tun Sie dies bitte. Vielen Dank

    GoogleMap map;


    private static Location mLastLocation;
    private static GoogleApiClient mGoogleApiClient;

    static double x3;
    static double x4;
    LatLng userloc;



@Override
public void onConnected(Bundle connectionHint) {
    mLastLocation = LocationServices.FusedLocationApi.getLastLocation(
            mGoogleApiClient);
    if (mLastLocation != null) {
        x3 = mLastLocation.getLatitude();
        x4 = mLastLocation.getLongitude();
        userloc = new LatLng(x3,x4);

        txtPlateno.setText(String.valueOf(x3+" - "+x4)); // PRINT TEST ONLY WITH CORRECT RESULT

    }
}






private static Spot[] SPOTS_ARRAY = new Spot[]{

    new Spot("YOU ARE HERE", "DESC ", "", new LatLng(x3, x4)), // NOT SHOWN IN MAP AT ALL

            new Spot("Besabella Parking Lot",
                    "Address: Sta Cruz Labogon, Mandaue City\n " +
                            "Fee: \n " +
                            "No. of available space: \n " +
                            "Distance:" + x3 + "KM", "", new LatLng(10.351763, 123.953683)),
            // TESTING x3 ON DISTANCE WITH RESULT 0.0

};

Antworten auf die Frage(2)

Ihre Antwort auf die Frage