Android Pobierz Lokalizacja Adres z geocoder w usłudze

głosy
1

I po to , aby uzyskać położenie współrzędnych i adres

Więc tu swój aktualizowanie Lokalizacja współrzędne szerokości i długości geograficznej na każde 10 sekund

Próbuję uzyskać Lokalizacja Adres wraz z nimi

Tutaj, aby uzyskać adres Używam Const klasę

public class Const {

public static String getCompleteAddressString(Context m_context, double LATITUDE, double LONGITUDE) {
    String strAdd = ;
    Geocoder geocoder = new Geocoder(m_context, Locale.getDefault());
    try {
        List<Address> addresses = geocoder.getFromLocation(LATITUDE, LONGITUDE, 1);
        if (addresses != null) {
            Address returnedAddress = addresses.get(0);
            StringBuilder strReturnedAddress = new StringBuilder();

            for (int i = 0; i < returnedAddress.getMaxAddressLineIndex(); i++) {
                strReturnedAddress.append(returnedAddress.getAddressLine(i)).append(\n);
            }
            strAdd = strReturnedAddress.toString();
            Log.v(My Current location add,  + strAdd.toString());
        }
    } catch (Exception e) {
        e.printStackTrace();
        Toast.makeText(m_context, Sorry, Your location cannot be retrieved ! + e.getMessage(), Toast.LENGTH_SHORT).show();

    }
    return strAdd;
}
}

Na teraz i główny przedmiot Aby uzyskać adres używam

private void updateUI() {
mLatitudeTextView.setText(String.format(%s: %f, mLatitudeLabel,
        mCurrentLocation.getLatitude()));
mLongitudeTextView.setText(String.format(%s: %f, mLongitudeLabel,
        mCurrentLocation.getLongitude()));
mLastUpdateTimeTextView.setText(String.format(%s: %s, mLastUpdateTimeLabel,
        mLastUpdateTime));

//For Address

mLocAddTextView.setText(String.format(%s: %s, mLocAddressLabel,
Const.getCompleteAddressString(this, mCurrentLocation.getLatitude(), mCurrentLocation.getLongitude())));
 }

Ale tu jego wyświetla nic może ktoś zasugerować mi Co złego w tym

Utwórz 27/02/2018 o 07:54
źródło użytkownik
W innych językach...                            


1 odpowiedzi

głosy
1

Twój kod jest idealny

Spróbuj to w swoim Const class

strReturnedAddress .append(returnedAddress.getAddressLine(0)).append("\n");

Jeśli chcesz użyć kodu pocztowego, lokalizację i kraj .. itp ... Użyj

List<Address> addresses = geocoder.getFromLocation(LATITUDE, LONGITUDE, 1);
if (addresses != null) {
    Address returnedAddress = addresses.get(0);
    StringBuilder strReturnedAddress = new StringBuilder("");
    for (int i = 0; i < returnedAddress.getMaxAddressLineIndex(); i++) {
                  strReturnedAddress.append(returnedAddress.getAddressLine(i)).append("\n");
    }
        strReturnedAddress .append(returnedAddress.getAddressLine(0)).append("\n");
        strReturnedAddress .append(returnedAddress.getLocality()).append("\n");
        strReturnedAddress .append(returnedAddress.getPostalCode()).append("\n");
        strReturnedAddress .append(returnedAddress.getCountryName());
    strAdd  = strReturnedAddress.toString();
    Log.v("My Current location add", "" + streturnedAddressd.toString());
}

Aby uzyskać adres geocoder śledzić Android Geokodując Lokalizacja

Odpowiedział 28/02/2018 o 08:07
źródło użytkownik

Cookies help us deliver our services. By using our services, you agree to our use of cookies. Learn more