So erhalten Sie die GPS-Position für Android

Prost, ich versuche den aktuellen GPS-Standort über Android zu ermitteln. ich folgtedieses Tutorial undVogellas Artikel auch. Obwohl es nicht funktioniert. Bei Verwendung von LocationManager.NETWORK_PROVIDER erhalte ich immer einen Breitengrad von 51 und einen Längengrad von 9 - egal wo ich stehe. Bei Verwendung von LocationManager.GPS_PROVIDER erhalte ich überhaupt nichts.

Obwohl bei Verwendung von GMaps alles funktioniert: S Keine Ahnung warum. Wie kann ich den aktuellen GPS-Standort wie bei GMaps ermitteln?

Hier ist mein Code:

package com.example.gpslocation;

import android.location.Location;
import android.location.LocationListener;
import android.location.LocationManager;
import android.os.Bundle;
import android.app.Activity;
import android.content.Context;
import android.util.Log;
import android.view.Menu;

public class GPS_Location extends Activity implements LocationListener {

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_gps__location);

    LocationManager locationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
    locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 0, 0, this);
}

@Override
public boolean onCreateOptionsMenu(Menu menu) {
    // Inflate the menu; this adds items to the action bar if it is present.
    getMenuInflater().inflate(R.menu.gps__location, menu);
    return true;
}

@Override
public void onLocationChanged(Location location) {
    // TODO Auto-generated method stub

    int latitude = (int) (location.getLatitude());
    int longitude = (int) (location.getLongitude());

    Log.i("Geo_Location", "Latitude: " + latitude + ", Longitude: " + longitude);
}

@Override
public void onProviderDisabled(String provider) {
    // TODO Auto-generated method stub

}

@Override
public void onProviderEnabled(String provider) {
    // TODO Auto-generated method stub

}

@Override
public void onStatusChanged(String provider, int status, Bundle extras) {
    // TODO Auto-generated method stub

}

}

Antworten auf die Frage(5)

Ihre Antwort auf die Frage