Android getMaxAddressLineIndex returns 0 for line 1

后端 未结 4 2117
忘掉有多难
忘掉有多难 2021-02-13 05:43

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: <

4条回答
  •  执念已碎
    2021-02-13 06:42

    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));
    

提交回复
热议问题