найти текущую широту и долготу местоположения в Android [дубликат]
На этот вопрос уже есть ответ здесь:
Какой самый простой и надежный способ узнать текущее местоположение пользователя на Android? 26 ответовЯ хочу найти широту и долготу моего текущего местоположения в приложении для Android. Мне просто нужно, когда я стабильно с моим телефоном.
Мой код:
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);
}
После запуска на эмуляторе я всегда нахожу "местоположение не найдено". Почему это так?