Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android Geocoder returning empty address

I am trying to get location address from Geocoder, I am able to get latitude and longitude but it returning address with zero length.

Here is my code snippet

            double longi = location.getLongitude();
            double latt = location.getLatitude();

            Geocoder geocoder = new Geocoder(getApplicationContext(), Locale.ENGLISH);

            String add="";
            try {


                List<Address> address = geocoder.getFromLocation(latt/1E6,longi/1E6, 1);


                System.out.println("in location listener "+address.size());


                int i=0;

                if(address.size()>0)
                {
                    for(i=0;i<address.get(0).getMaxAddressLineIndex();i++)
                    {
                        add += address.get(0).getAddressLine(i);
                    }


                    Toast toast  = new Toast(getApplicationContext());
                    toast.makeText(getApplicationContext(), add, Toast.LENGTH_LONG).show();
                }   

            } catch (IOException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }

Please help me to get it correct. Thanks in advance!

like image 576
Aniruddh Ambarkar Avatar asked May 08 '12 06:05

Aniruddh Ambarkar


1 Answers

The Geocoder query methods will return an empty list if there no backend service in the platform. Use the isPresent() method to determine whether a Geocoder implementation exists.

See the Geocoder documentation for more information.

like image 59
Vishesh Chandra Avatar answered Oct 23 '22 18:10

Vishesh Chandra