Android getMaxAddressLineIndex returns 0 for line 1

Viewed 2346

For some reason the implementation of getMaxAddressLineIndex has recently changed. Now this method returns 0 for line 1.

I have an existing code, which used to work: i<address.getMaxAddressLineIndex(). However, it is broken somehow.

enter image description here

I don't know if it is due to the new Google Api or something else.

Can someone please confirm me here what is going on?

4 Answers

As user8533943 has pointed out above the implementation has been changed surreptitiously. However I am of the opinion that

geocoder.getFromLocation()

has changed it's implementation. It returns a list of addresses and each address consists of address lines. But as far as I could see when I compiled with version 26 of the SDK there aren't "address lines" being returned but just one line for every address.

So if you have just one address then

getMaxAddressLineIndex()

would in fact return 0

Update your implementation as follows to use a <= comparison.

for(int i = 0; i <= address.getMaxAddressLineIndex(); i++) {
                addressFragments.add(address.getAddressLine(i));
Related