Android ottenere Località Indirizzo con Geocoder in un Servizio

voti
1

Ho seguito questo per ottenere la posizione di coordinate e indirizzo

Così qui è ottenere aggiornamenti sulla posizione Coordinate latitudine e la longitudine Ogni 10 secondi

Sto cercando di ottenere Località Indirizzo insieme a loro

Qui per ottenere l'indirizzo che sto usando Const classe

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;
}
}

E ora a Main Activity per ottenere l'indirizzo che sto usando

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())));
 }

Ma qui il suo display nulla può uno mi suggeriscono che cosa è sbagliato in questo

È pubblicato 27/02/2018 alle 07:54
fonte dall'utente
In altre lingue...                            


1 risposte

voti
1

Il codice è perfetto

Prova questo nella vostra Const class

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

Se si desidera utilizzare il codice postale, località e paese .. ecc ... uso

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());
}

Per ottenere l'indirizzo Geocoder seguire Android Geocode Località

Risposto il 28/02/2018 a 08:07
fonte dall'utente

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