Java Code Examples for android.location.Address#setSubAdminArea()

The following examples show how to use android.location.Address#setSubAdminArea() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: NominatimGeocoder.java    From callerid-for-android with GNU General Public License v3.0 6 votes vote down vote up
protected List<Address> parseResponse(final Place[] places) {
	final List<Address> ret = new ArrayList<Address>(places.length);
	
	for(final Place place : places){
		final Address address = new Address(Locale.getDefault());
		ret.add(address);
		
		address.setThoroughfare(place.getDisplayName());
		address.setLatitude(place.getLatitude());
		address.setLongitude(place.getLongitude());
		final Place.Address placeAddress = place.getAddress();
		if(placeAddress!=null){
			address.setCountryCode(placeAddress.getCountryCode());
			address.setCountryName(placeAddress.getCountry());
			address.setPostalCode(placeAddress.getPostalCode());
			address.setSubAdminArea(placeAddress.getCountry());
		}
	}
	
	return ret;
}
 
Example 2
Source File: NominatimLocationService.java    From your-local-weather with GNU General Public License v3.0 4 votes vote down vote up
private Address parseResponse(Locale locale, JSONObject result) throws JSONException {
    if (!result.has(WIRE_LATITUDE) || !result.has(WIRE_LONGITUDE) ||
            !result.has(WIRE_ADDRESS)) {
        return null;
    }
    Address address = new Address(locale);
    address.setLatitude(result.getDouble(WIRE_LATITUDE));
    address.setLongitude(result.getDouble(WIRE_LONGITUDE));

    JSONObject a = result.getJSONObject(WIRE_ADDRESS);

    address.setThoroughfare(a.optString(WIRE_THOROUGHFARE));
    address.setSubLocality(a.optString(WIRE_SUBLOCALITY));
    address.setPostalCode(a.optString(WIRE_POSTALCODE));
    address.setSubAdminArea(a.optString(WIRE_SUBADMINAREA));
    address.setAdminArea(a.optString(WIRE_ADMINAREA));
    address.setCountryName(a.optString(WIRE_COUNTRYNAME));
    address.setCountryCode(a.optString(WIRE_COUNTRYCODE));

    if (a.has(WIRE_LOCALITY_CITY)) {
        address.setLocality(a.getString(WIRE_LOCALITY_CITY));
    } else if (a.has(WIRE_LOCALITY_TOWN)) {
        address.setLocality(a.getString(WIRE_LOCALITY_TOWN));
    } else if (a.has(WIRE_LOCALITY_VILLAGE)) {
        address.setLocality(a.getString(WIRE_LOCALITY_VILLAGE));
    }

    if (formatter != null) {
        Map<String, String> components = new HashMap<>();
        for (String s : new IterableIterator<>(a.keys())) {
            components.put(s, String.valueOf(a.get(s)));
        }
        String[] split = formatter.formatAddress(components).split("\n");
        for (int i = 0; i < split.length; i++) {
            address.setAddressLine(i, split[i]);
        }

        address.setFeatureName(formatter.guessName(components));
    }

    return address;
}
 
Example 3
Source File: GeocoderNominatim.java    From PocketMaps with MIT License 4 votes vote down vote up
/**
 * Build an Android Address object from the Nominatim address in JSON
 * format. Current implementation is mainly targeting french addresses, and
 * will be quite basic on other countries.
 *
 * @param jResult ...
 * @return ...
 * @throws JSONException ...
 */
protected Address buildAndroidAddress(JSONObject jResult) throws JSONException {
    Address gAddress = new Address(mLocale);
    gAddress.setLatitude(jResult.getDouble("lat"));
    gAddress.setLongitude(jResult.getDouble("lon"));

    JSONObject jAddress = jResult.getJSONObject("address");

    int addressIndex = 0;
    if (jAddress.has("road")) {
        gAddress.setAddressLine(addressIndex++, jAddress.getString("road"));
        gAddress.setThoroughfare(jAddress.getString("road"));
    }
    if (jAddress.has("suburb")) {
        //gAddress.setAddressLine(addressIndex++, jAddress.getString("suburb"));
        //not kept => often introduce "noise" in the address.
        gAddress.setSubLocality(jAddress.getString("suburb"));
    }
    if (jAddress.has("postcode")) {
        gAddress.setAddressLine(addressIndex++, jAddress.getString("postcode"));
        gAddress.setPostalCode(jAddress.getString("postcode"));
    }

    if (jAddress.has("city")) {
        gAddress.setAddressLine(addressIndex++, jAddress.getString("city"));
        gAddress.setLocality(jAddress.getString("city"));
    } else if (jAddress.has("town")) {
        gAddress.setAddressLine(addressIndex++, jAddress.getString("town"));
        gAddress.setLocality(jAddress.getString("town"));
    } else if (jAddress.has("village")) {
        gAddress.setAddressLine(addressIndex++, jAddress.getString("village"));
        gAddress.setLocality(jAddress.getString("village"));
    }

    if (jAddress.has("county")) { //France: departement
        gAddress.setSubAdminArea(jAddress.getString("county"));
    }
    if (jAddress.has("state")) { //France: region
        gAddress.setAdminArea(jAddress.getString("state"));
    }
    if (jAddress.has("country")) {
        gAddress.setAddressLine(addressIndex++, jAddress.getString("country"));
        gAddress.setCountryName(jAddress.getString("country"));
    }
    if (jAddress.has("country_code"))
        gAddress.setCountryCode(jAddress.getString("country_code"));

    /* Other possible OSM tags in Nominatim results not handled yet: subway,
     * golf_course, bus_stop, parking,... house, house_number, building
     * city_district (13e Arrondissement) road => or highway, ... sub-city
     * (like suburb) => locality, isolated_dwelling, hamlet ...
     * state_district */

    return gAddress;
}
 
Example 4
Source File: BackendService.java    From NominatimGeocoderBackend with Apache License 2.0 4 votes vote down vote up
private Address parseResponse(Locale locale, JSONObject result) throws JSONException {
    if (!result.has(WIRE_LATITUDE) || !result.has(WIRE_LONGITUDE) ||
            !result.has(WIRE_ADDRESS)) {
        return null;
    }
    Address address = new Address(locale);
    address.setLatitude(result.getDouble(WIRE_LATITUDE));
    address.setLongitude(result.getDouble(WIRE_LONGITUDE));

    JSONObject a = result.getJSONObject(WIRE_ADDRESS);

    address.setThoroughfare(a.optString(WIRE_THOROUGHFARE));
    address.setSubLocality(a.optString(WIRE_SUBLOCALITY));
    address.setPostalCode(a.optString(WIRE_POSTALCODE));
    address.setSubAdminArea(a.optString(WIRE_SUBADMINAREA));
    address.setAdminArea(a.optString(WIRE_ADMINAREA));
    address.setCountryName(a.optString(WIRE_COUNTRYNAME));
    address.setCountryCode(a.optString(WIRE_COUNTRYCODE));

    if (a.has(WIRE_LOCALITY_CITY)) {
        address.setLocality(a.getString(WIRE_LOCALITY_CITY));
    } else if (a.has(WIRE_LOCALITY_TOWN)) {
        address.setLocality(a.getString(WIRE_LOCALITY_TOWN));
    } else if (a.has(WIRE_LOCALITY_VILLAGE)) {
        address.setLocality(a.getString(WIRE_LOCALITY_VILLAGE));
    }

    if (formatter != null) {
        Map<String, String> components = new HashMap<>();
        for (String s : new IterableIterator<>(a.keys())) {
            components.put(s, String.valueOf(a.get(s)));
        }
        String[] split = formatter.formatAddress(components).split("\n");
        for (int i = 0; i < split.length; i++) {
            Log.d(TAG, split[i]);
            address.setAddressLine(i, split[i]);
        }

        address.setFeatureName(formatter.guessName(components));
    }

    return address;
}