get Address String - Android android.location

Android examples for android.location:Address

Description

get Address String

Demo Code

import android.location.Address;

public class Main{

    public static String getAddressString(Address address) {
        if (address.getMaxAddressLineIndex() == -1) {
            return null;
        }//w  w  w  .  jav  a 2  s .  c  o m
        StringBuilder addressStringBuilder = new StringBuilder();
        for (int i = 0; i <= address.getMaxAddressLineIndex(); i++) {
            addressStringBuilder.append(address.getAddressLine(i));
            if (i != address.getMaxAddressLineIndex()) {
                addressStringBuilder.append(", ");
            }
        }
        return addressStringBuilder.toString();
    }

}

Related Tutorials