Finden Sie den aktuellen Standort Breiten- und Längengrad in Android [duplizieren]
Diese Frage hat hier bereits eine Antwort:
Was ist die einfachste und robusteste Methode, um den aktuellen Standort des Benutzers auf Android abzurufen? 26 AntwortenIch möchte den Breiten- und Längengrad meines aktuellen Standorts in einer Android-Anwendung ermitteln. Ich brauche es nur, wenn ich mit meinem Handy stabil bin.
Mein Code ist:
LocationManager locationManager;
locationManager = (LocationManager)getSystemService
(Context.LOCATION_SERVICE);
Location location = locationManager.getLastKnownLocation
(LocationManager.GPS_PROVIDER);
locationManager.requestLocationUpdates(
LocationManager.GPS_PROVIDER,0,0,(LocationListener) this);
updateWithNewLocation(location);
}
private void updateWithNewLocation(Location location) {
TextView myLocationText = (TextView)findViewById(R.id.myLocationText);
String latLongString;
if (location != null) {
double lat = location.getLatitude();
double lng = location.getLongitude();
latLongString = "Lat:" + lat + "\nLong:" + lng;
} else {
latLongString = "No location found";
}
myLocationText.setText("Your Current Position is:\n" +
latLongString);
}
Nach dem Ausführen auf dem Emulator finde ich immer "no location found". Warum ist das so?