title: How to get street address from latitude and longitude
body: <p>I am writing a program that gets the complete location from google maps, I managed to get latitude and longitude, but when it comes to address, I did everything as mentioned in different websites but I get an empty List.</p>
  
  <p>Here is the code : </p>
  
  <p>This is the function that saves the address in a list</p>
  
  <pre><code>public List&lt;Address&gt; getAddress() {
      try {
          Geocoder geocoder;
          List&lt;Address&gt; addresses;
          double latitude, longitude;
          latitude = Double.parseDouble(lat);
          longitude =  Double.parseDouble(lng);
          System.out.println(latitude + " / " + longitude);
          geocoder = new Geocoder(this);
          if (latitude != 0 || longitude != 0) {
              addresses = geocoder.getFromLocation(latitude ,
                      longitude, 2);
              return addresses;
          } else {
              Toast.makeText(this, "latitude and longitude are null",
                      Toast.LENGTH_LONG).show();
              return null;
          }
      } catch (Exception e) {
          e.printStackTrace();
          return null;
      }
  }
  </code></pre>
  
  <p>And here is the function that calls it : </p>
  
  <pre><code>@Override
  public void onLocationChanged(Location location) {
  
      lng = location.getLongitude() + "";
      lat = location.getLatitude() + "";
  
      try
      {
          getAddress();
      }
      catch (Exception e)
      {
          System.out.println("Can't Call getAddress()");
      }
  
      gotoLocation(location);
  
  }
  </code></pre>
  
  <p>This is the given error each time the onLocationChanged() is called</p>
  
  <blockquote>
    <p>06-16 12:06:23.595: W/System.err(28123): java.lang.IndexOutOfBoundsException: Invalid index 0, size is 0
    06-16 12:06:23.595: W/System.err(28123):    at java.util.ArrayList.throwIndexOutOfBoundsException(ArrayList.java:255)
    06-16 12:06:23.595: W/System.err(28123):    at java.util.ArrayList.get(ArrayList.java:308)
    06-16 12:06:23.595: W/System.err(28123):    at com.MOS.fastfood.MapActivity.getAddress(MapActivity.java:559)
    06-16 12:06:23.595: W/System.err(28123):    at com.MOS.fastfood.MapActivity.onLocationChanged(MapActivity.java:522)
    06-16 12:06:23.595: W/System.err(28123):    at com.google.android.gms.internal.zzpe$zza.handleMessage(Unknown Source)
    06-16 12:06:23.595: W/System.err(28123):    at android.os.Handler.dispatchMessage(Handler.java:99)
    06-16 12:06:23.600: W/System.err(28123):    at android.os.Looper.loop(Looper.java:176)
    06-16 12:06:23.600: W/System.err(28123):    at android.app.ActivityThread.main(ActivityThread.java:5419)
    06-16 12:06:23.600: W/System.err(28123):    at java.lang.reflect.Method.invokeNative(Native Method)
    06-16 12:06:23.600: W/System.err(28123):    at java.lang.reflect.Method.invoke(Method.java:525)
    06-16 12:06:23.600: W/System.err(28123):    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1046)
    06-16 12:06:23.600: W/System.err(28123):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:862)
    06-16 12:06:23.600: W/System.err(28123):    at dalvik.system.NativeStart.main(Native Method)</p>
  </blockquote>
  
  <p>This is the manifest</p>
  
  <pre><code>    &lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;manifest xmlns:android="http://schemas.android.com/apk/res/android"
  package="com.MOS.fastfood"
  android:versionCode="1"
  android:versionName="1.0" &gt;
  
  &lt;uses-sdk
      android:minSdkVersion="11"
      android:targetSdkVersion="22" /&gt;
  
  &lt;!-- added permission manually to reveice MAP --&gt;
  &lt;permission
      android:name="com.MOS.fastfood.permission.MAPS_RECEIVE"
      android:protectionLevel="signature" &gt;
  &lt;/permission&gt;
  
  &lt;!-- permissions to access internet --&gt;
  &lt;uses-permission android:name="android.permission.INTERNET" /&gt;
  &lt;uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" /&gt;
  &lt;uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" /&gt;
  &lt;uses-permission android:name="com.google.android.providers.gsf.permission.READ_GSERVICES"/&gt;
  
  &lt;!-- important permissions to fetch map from google --&gt;
  &lt;uses-permission android:name="com.MOS.fastfood.permission.MAPS_RECEIVE" /&gt;
  &lt;uses-permission android:name="com.google.android.providers.gsf.permission.READ_GSERVICES" /&gt;
  
  &lt;!-- only devices that support version 2.0 of openGL can download, for graphics --&gt;
  &lt;uses-feature
      android:glEsVersion="0x00020000"
      android:required="true" /&gt;
  
  &lt;!-- two permissions used to determine the current location using network towers and gps --&gt;
  &lt;uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" /&gt;
  &lt;uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" /&gt;
  
  &lt;application
      android:allowBackup="true"
      android:icon="@drawable/ic_launcher"
      android:label="@string/app_name"
      android:theme="@style/AppTheme" &gt;
      &lt;activity
          android:name=".MainActivity"
          android:label="@string/app_name" &gt;
          &lt;intent-filter&gt;
              &lt;action android:name="android.intent.action.MAIN" /&gt;
  
              &lt;category android:name="android.intent.category.LAUNCHER" /&gt;
          &lt;/intent-filter&gt;
      &lt;/activity&gt;
  
      &lt;!-- ADDING THE DEBUGGING KEY --&gt;
      &lt;meta-data
          android:name="com.google.android.maps.v2.API_KEY"
          android:value="***" /&gt;
  
      &lt;!-- THIS META DATA ALLOWS "ISGOOGLEPLAYSERVICES ENABLED" TO FUNCTION WITHOUT CRASH --&gt;
      &lt;meta-data
          android:name="com.google.android.gms.version"
          android:value="@integer/google_play_services_version" /&gt;
  
      &lt;activity
          android:name=".AddRestaurantActivity"
          android:label="@string/title_activity_add_restaurant" &gt;
      &lt;/activity&gt;
      &lt;activity
          android:name=".FacebookLoginActivity"
          android:label="@string/title_activity_facebook_login" &gt;
      &lt;/activity&gt;
      &lt;activity
          android:name=".ListActivity"
          android:label="@string/title_activity_list" &gt;
      &lt;/activity&gt;
      &lt;activity
          android:name=".MapActivity"
          android:label="@string/title_activity_map" &gt;
      &lt;/activity&gt;
      &lt;activity
          android:name=".RestaurantInfoActivity"
          android:label="@string/title_activity_rate" &gt;
      &lt;/activity&gt;
      &lt;activity
          android:name=".Loader"
          android:label="@string/title_activity_loader" &gt;
      &lt;/activity&gt;
  &lt;/application&gt;
  
  &lt;/manifest&gt;
  </code></pre>