سؤال

I am trying to get the postcode / zip code using geocoder

List<Address> addresses = geocoder.getFromLocation(latitude, longitude, 1);
            if (addresses.size() == 1) {
                    Address address = addresses.get(0);
                    for (int i = 0; i < address.getMaxAddressLineIndex(); i++) {
                        addressString = addressString + address.getAddressLine(i) + "\n";
                    }
                    Log.e("TAG", "PostCode: " + address.getPostalCode());

addressString is upadated with the address - for example "12 Road Name, Town, Area, First 3 Characters of Postcode

However I want to get the PostCode characters separately so that I can use them elsewhere but address.getPostalCode() returns null value.

Thank You.

هل كانت مفيدة؟

المحلول

I realise that this does return the post code but not always, as it may not be available.

address.getPostalCode();

Thanks.

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top