get Address String from a List of Address - Android Map

Android examples for Map:Address

Description

get Address String from a List of Address

Demo Code


//package com.java2s;
import android.location.Address;
import java.util.List;

public class Main {
    public static String getAddressString(List<Address> addresses) {
        String locality = null;/*from w w w.  j a v a  2 s  .  c  o m*/

        for (Address address : addresses) {
            String subLocality = address.getSubLocality();
            if (subLocality != null || locality == null) {
                locality = address.getLocality();
            }

            if (subLocality != null && locality != null) {
                return String.format("%s, %s", subLocality, locality);
            }
        }

        return locality;
    }
}

Related Tutorials