Android How to - Get Address line by line








Question

We would like to know how to get Address line by line.

Answer

import java.util.ArrayList;
import java.util.List;
//from   w w  w  .  j ava2 s .c o m
import android.location.Address;

public class Main {
  public static String buildAddress(final Address place) {
    List<String> parts = new ArrayList<>();
    for (int i = place.getMaxAddressLineIndex(); i >= 0; i--) {
      parts.add(place.getAddressLine(i));
    }
    StringBuilder bldr = new StringBuilder();
    for (String part : parts) {
        bldr.append(part);
    }
    return bldr.toString();
  }
}