title: Get Location Name by passing Latitude and Longitude in android
body: <p>I have written following code for getting location name :</p>
  
  <p><strong>UseGpsActivity.java</strong></p>
  
  <pre><code>public class UseGpsActivity extends Activity {
      /** Called when the activity is first created. */
      @Override
      public void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          setContentView(R.layout.main);
          /* Use the LocationManager class to obtain GPS locations */
          boolean gps_is_enabled = false;
          LocationManager mlocManager = (LocationManager) this
                  .getSystemService(Context.LOCATION_SERVICE);
          List&lt;String&gt; accessibleProviders = mlocManager.getProviders(true);
          gps_is_enabled = accessibleProviders != null
                  &amp;&amp; accessibleProviders.size() &gt; 0;
          Log.v("gps enabled", gps_is_enabled + "");
          LocationListener mlocListener = new MyLocationListener();
          // mlocManager.requestLocationUpdates(mlocManager.GPS_PROVIDER, 0, 0,
          // mlocListener);
          mlocManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 0, 0,
                  mlocListener);
          // mlocManager.set
      }
  
      /* Class My Location Listener */
  
      public class MyLocationListener implements LocationListener {
          @Override
          public void onProviderDisabled(String provider) {
              Toast.makeText(getApplicationContext(), "Gps Disabled", 5000)
                      .show();
              Log.v("gps", "gps disabled");
          }
  
          @Override
          public void onProviderEnabled(String provider) {
              Toast.makeText(getApplicationContext(), "Gps Enabled", 5000).show();
              Log.v("gps", "gps enabled");
          }
  
          @Override
          public void onStatusChanged(String provider, int status, Bundle extras) {
  
          }
  
          @Override
          public void onLocationChanged(Location loc) {
              // TODO Auto-generated method stub
              loc.getLatitude();
              loc.getLongitude();
              String Text = "My current location is: " + "Latitud = "
                      + loc.getLatitude() + "Longitud = " + loc.getLongitude();
              Toast.makeText(getApplicationContext(), Text, Toast.LENGTH_SHORT)
                      .show();
              Geocoder gcd = new Geocoder(UseGpsActivity.this,
                      Locale.getDefault());
              List&lt;Address&gt; addresses = null;
              try {
                  addresses = gcd.getFromLocation(loc.getLatitude(),
                          loc.getLongitude(), 1);
  
              } catch (IOException e) {
                  // TODO Auto-generated catch block
                  e.printStackTrace();
              }
              if (addresses != null) {
                  if (addresses.size() &gt; 0) {
                      Log.v("Addresses : ", addresses.get(0).getLocality() + "");
                      Toast.makeText(
                              getApplicationContext(),
                              "Addresses : " + addresses.get(0).getLocality()
                                      + "", Toast.LENGTH_LONG).show();
                      Log.v("gps", Text + " " + addresses.get(0).getLocality()
                              + "");
                  }
              } else {
                  Log.v("addresses ", "NULL");
              }
          }
      }/* End of Class MyLocationListener */
  </code></pre>
  
  <p><strong>Code on Manifest.xml</strong></p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;manifest xmlns:android="http://schemas.android.com/apk/res/android"
      package="demo.usegps"
      android:versionCode="1"
      android:versionName="1.0" &gt;
  
      &lt;uses-sdk android:minSdkVersion="4" /&gt;
  
      &lt;uses-permission android:name="android.permission.INTERNET" /&gt;
      &lt;uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/&gt;
      &lt;uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" /&gt;
      &lt;uses-permission android:name="android.permission.ACCESS_MOCK_LOCATION" /&gt;
      &lt;uses-permission android:name="android.permission.ACCESS_LOCATION" /&gt;
      &lt;uses-permission android:name="android.permission.ACCESS_GPS" /&gt;
      &lt;uses-permission android:name="android.permission.ACCESS_ASSISTED_GPS" /&gt;
      &lt;uses-permission android:name="android.permission.SET_TIME_ZONE" /&gt;
  
      &lt;application
          android:icon="@drawable/ic_launcher"
          android:label="@string/app_name" &gt;
          &lt;activity
              android:name=".UseGpsActivity"
              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;/application&gt;
  
  &lt;/manifest&gt;
  </code></pre>
  
  <p>When i use geo fix (<code>geo fix -122.084094 37.422006</code>) i get toast displayed with lat and lng , but i get following message on logcat :</p>
  
  <pre><code>01-19 13:32:48.991: W/System.err(751): java.io.IOException: Service not Available
  01-19 13:32:48.991: W/System.err(751):  at android.location.Geocoder.getFromLocation(Geocoder.java:117)
  01-19 13:32:49.001: W/System.err(751):  at demo.usegps.UseGpsActivity$MyLocationListener.onLocationChanged(UseGpsActivity.java:74)
  01-19 13:32:49.001: W/System.err(751):  at android.location.LocationManager$ListenerTransport._handleMessage(LocationManager.java:191)
  01-19 13:32:49.001: W/System.err(751):  at android.location.LocationManager$ListenerTransport.access$000(LocationManager.java:124)
  01-19 13:32:49.001: W/System.err(751):  at android.location.LocationManager$ListenerTransport$1.handleMessage(LocationManager.java:140)
  01-19 13:32:49.001: W/System.err(751):  at android.os.Handler.dispatchMessage(Handler.java:99)
  01-19 13:32:49.001: W/System.err(751):  at android.os.Looper.loop(Looper.java:123)
  01-19 13:32:49.001: W/System.err(751):  at android.app.ActivityThread.main(ActivityThread.java:4627)
  01-19 13:32:49.001: W/System.err(751):  at java.lang.reflect.Method.invokeNative(Native Method)
  01-19 13:32:49.001: W/System.err(751):  at java.lang.reflect.Method.invoke(Method.java:521)
  01-19 13:32:49.001: W/System.err(751):  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
  01-19 13:32:49.011: W/System.err(751):  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
  01-19 13:32:49.011: W/System.err(751):  at dalvik.system.NativeStart.main(Native Method)
  01-19 13:32:49.011: V/addresses(751): NULL
  </code></pre>
  
  <p>Which service do i need to add or call in my code ?? </p>