0

I want to get a list of the 5 adresses more similar to the string passed, but something is not working.

For example, if I write "avenida" there are thousands of "avenida" streets in spain, but the method getFromLocationName returns 0.

private void getAddressInfo(Context context, String locationName){
        Geocoder geocoder = new Geocoder(context);
        try {
        List<Address> a = geocoder.getFromLocationName(locationName, 5);
        for(int i=0;i<a.size();i++){
            String city = a.get(0).getLocality();
            String country = a.get(0).getCountryName();
            String address = a.get(0).getAddressLine(0); // If any additional address line present than only, check with max available address lines by getMaxAddressLineIndex()
            addressList.add(address+", "+city+", "+country);
        }
    } catch (IOException e) {
        e.printStackTrace();
    }
}

Is there something wrong in the code?

NullPointerException
  • 36,107
  • 79
  • 222
  • 382

1 Answers1

0

I just confirmed this in code; the way it works is you give it a valid place name, like an address. It does not need a city. then it should give you a list of as many as it finds. not as useful as expected. A street or business name does not seem to work. :-(

if i do 2000 east main without a city i get a hit

if i do east main i get 0

I am going to use this instead