geocoder.getFromLocation returning null

11,580

I find the solution... hold Ctrl on getFromLocation() and go to Geocoder.class . then download sources for your android API and restart your project. then you see its work

Share:
11,580
piyush
Author by

piyush

Updated on June 04, 2022

Comments

  • piyush
    piyush almost 2 years

    my code :

                     try
                    {
    
                                Geocoder geocoder;
                            List<Address> addresses;
    
                geocoder = new Geocoder(LocationActivity.this, Locale.getDefault());
    
                addresses = geocoder.getFromLocation(longitude,latitude,1);
    
                Toast.makeText(LocationActivity.this, addresses.size() + "", Toast.LENGTH_LONG).show();
    
                String address = addresses.get(0).getAddressLine(0);
                String city = addresses.get(0).getAddressLine(0);
                String country = addresses.get(0).getAddressLine(0);
    
                Toast.makeText(LocationActivity.this, address + "  " + city + " " + country, Toast.LENGTH_LONG).show();
    
            }
            catch(Exception e)
            {
                Toast.makeText(LocationActivity.this,e.toString(), Toast.LENGTH_LONG).show();
            }
    

    this is my code to get address from longitude and latitude. but every time addresses.size returns 0

    can anyone help me for this

  • Sandeep P
    Sandeep P over 11 years
    check your lat long valid or not
  • piyush
    piyush over 11 years
    i checked it... and its valid
  • Sandeep P
    Sandeep P over 11 years
    finally try with targetsdk version 15
  • piyush
    piyush over 11 years
    nope... whats thats... can u give a full description.. my api is 8 and android 2.2
  • piyush
    piyush over 11 years
    nope.. i m not getting any exception... but addresses size always 0
  • piyush
    piyush over 11 years
    but i m creating my application in targetsdk 8 (2.2)... now what i have to do ??
  • Sandeep P
    Sandeep P over 11 years
    Right click on project, go to properties(in the end), select the android at right side , select project-build target (sel max) which contain google, and mention this in manifest <uses-sdk android:minSdkVersion="8" android:targetSdkVersion="15" /> ..... if still it is not working , may be ur device fault
  • piyush
    piyush over 11 years
    but my device have android 2.2 OS.. if i change target then still i can run this app in android 2.2 ?
  • Sandeep P
    Sandeep P over 11 years
    yes u can run it, target sdk is not a matter make sure that min sdk is 8 so u can run in 2.2
  • Sandeep P
    Sandeep P over 11 years
    <uses-sdk android:minSdkVersion="8" android:targetSdkVersion="15" />
  • piyush
    piyush over 11 years
    i change the target to 15 and i tried to other device... still not working... still its give arrayIndexOutofBound Exception..
  • Ajay Pandya
    Ajay Pandya almost 9 years
    have you start location access from settings
  • John Hughes
    John Hughes over 5 years
    so how to install the backend service