Example usage for android.location Address setPostalCode

List of usage examples for android.location Address setPostalCode

Introduction

In this page you can find the example usage for android.location Address setPostalCode.

Prototype

public void setPostalCode(String postalCode) 

Source Link

Document

Sets the postal code of the address to the given String, which may be null.

Usage

From source file:org.microg.networklocation.backends.mapquest.NominatimGeocodeSource.java

private Address parseResponse(Locale locale, JSONObject result) throws JSONException {
    if (!result.has(WIRE_LATITUDE) || !result.has(WIRE_LONGITUDE) || !result.has(WIRE_ADDRESS)) {
        return null;
    }/*from  ww  w. ja  v  a2 s  . com*/
    Address address = new Address(locale);
    address.setLatitude(result.getDouble(WIRE_LATITUDE));
    address.setLatitude(result.getDouble(WIRE_LONGITUDE));

    int line = 0;
    JSONObject a = result.getJSONObject(WIRE_ADDRESS);

    if (a.has(WIRE_THOROUGHFARE)) {
        address.setAddressLine(line++, a.getString(WIRE_THOROUGHFARE));
        address.setThoroughfare(a.getString(WIRE_THOROUGHFARE));
    }
    if (a.has(WIRE_SUBLOCALITY)) {
        address.setSubLocality(a.getString(WIRE_SUBLOCALITY));
    }
    if (a.has(WIRE_POSTALCODE)) {
        address.setAddressLine(line++, a.getString(WIRE_POSTALCODE));
        address.setPostalCode(a.getString(WIRE_POSTALCODE));
    }
    if (a.has(WIRE_LOCALITY_CITY)) {
        address.setAddressLine(line++, a.getString(WIRE_LOCALITY_CITY));
        address.setLocality(a.getString(WIRE_LOCALITY_CITY));
    } else if (a.has(WIRE_LOCALITY_TOWN)) {
        address.setAddressLine(line++, a.getString(WIRE_LOCALITY_TOWN));
        address.setLocality(a.getString(WIRE_LOCALITY_TOWN));
    } else if (a.has(WIRE_LOCALITY_VILLAGE)) {
        address.setAddressLine(line++, a.getString(WIRE_LOCALITY_VILLAGE));
        address.setLocality(a.getString(WIRE_LOCALITY_VILLAGE));
    }
    if (a.has(WIRE_SUBADMINAREA)) {
        address.setAddressLine(line++, a.getString(WIRE_SUBADMINAREA));
        address.setSubAdminArea(a.getString(WIRE_SUBADMINAREA));
    }
    if (a.has(WIRE_ADMINAREA)) {
        address.setAddressLine(line++, a.getString(WIRE_ADMINAREA));
        address.setAdminArea(a.getString(WIRE_ADMINAREA));
    }
    if (a.has(WIRE_COUNTRYNAME)) {
        address.setAddressLine(line++, a.getString(WIRE_COUNTRYNAME));
        address.setCountryName(a.getString(WIRE_COUNTRYNAME));
    }
    if (a.has(WIRE_COUNTRYCODE)) {
        address.setCountryCode(a.getString(WIRE_COUNTRYCODE));
    }

    return address;
}