使用特殊字符反转地理编码地址

时间:2015-01-12 10:40:52

标签: android location android-location

我想把一个字符串地址反转为Lat和Long。

try {
                        List<Address> foundGeocode;
                       /* find the addresses  by using getFromLocationName() method with the given address*/
                        foundGeocode = new Geocoder(getActivity()).getFromLocationName(URLEncoder.encode(searchResult.getPlaces().get(position).getAddress(),"UTF-8"), 1);
                        if (!foundGeocode.isEmpty()) {
                            foundGeocode.get(0).getLatitude(); //getting latitude
                            foundGeocode.get(0).getLongitude();//getting longitude


                            if (recentSearchList != null
                                    && !recentSearchList
                                    .contains(newPlaces(searchResult.getPlaces().get(position).getId(), searchResult.getPlaces().get(position).getAddress(),
                                            searchResult.getPlaces().get(position).getName(), searchResult.getPlaces().get(position).getReference())))
                                recentSearchList.add(0, new Places(
                                        searchResult.getPlaces().get(position).getId(), searchResult.getPlaces().get(position).getAddress(),
                                        searchResult.getPlaces().get(position).getName(), searchResult.getPlaces().get(position).getReference()));

                            if (recentSearchList.size() > 5)
                                recentSearchList = new ArrayList<Places>(
                                        recentSearchList.subList(0, 5));
                            mListner.onSearchFinished(new LatLng(foundGeocode.get(0).getLatitude(), foundGeocode.get(0).getLongitude()), searchPlace.getText().toString());
                        }
                    } catch (IOException e) {
                        e.printStackTrace();
                    } catch (IndexOutOfBoundsException e) {
                        e.printStackTrace();
                    }

代码工作正常。但是,当我试图解决“EPFO,B&amp; C Block Road Shalimar Bagh新德里德里印度”'foundGeocode.isEmpty()'是真的。对于带有特殊字符的地址,getFromLocationName()返回空。

0 个答案:

没有答案
相关问题