1

谁能告诉我这里出了什么问题。我正在尝试使用反向地理编码获取地址..`

if (locationGPS != null) {
                    list = geocoder.getFromLocation(locationGPS.getLatitude(),
                            locationGPS.getLongitude(), 3);

                    if (list != null) {
                        if (list.size() > 0) {
                            strZipcode = list.get(0).getPostalCode();
                            strAdminArea = list.get(0).getAdminArea();
                            strLocality = list.get(0).getLocality();
                            strAddressLine = list.get(0).getAddressLine(0);

                            Log.d(TAG, "list of address: "+ list);
                            Log.d(TAG, "Data: "+ mobileDataEnabled);
                            Log.d(TAG, "Data: "+ mobile);



                            int count = 0;
                            while ((strZipcode == null || strAdminArea == null
                                    || strLocality == null || (strAddressLine == null || strAddressLine == "USA"))
                                    && count < list.size()) {
                                strZipcode = list.get(count).getPostalCode();
                                strAdminArea = list.get(count).getAdminArea();
                                strLocality = list.get(count).getLocality();
                                strAddressLine = list.get(count)
                                        .getAddressLine(count);
                                count++;
                            }`

这东西工作正常,并给出了正确的地址。但有时它会为我试图检索的所有值给出 null,尽管事实上我已经检查了 null 值。我在这里遗漏了什么吗?

4

1 回答 1

0

反向地理编码器并不总是返回值。这听起来很奇怪,但事实就是这样。F0r 例如,如果您点击地址 5 次,您将无法幸运地获得所有点击的响应。您可能会得到 3 个。因此,解决方法可能是,而不是一次点击一个地理编码器,而是尝试将您的请求循环到 2 或 3 次或更多,其中一个请求将有望工作。

于 2013-07-05T06:04:18.023 回答