Reverse Geocoding in android
<p>hi frds here in this code i m getting exception like-"NO SERVICE AVIALBLE"...</p>

<p>My code is below...please help me...</p>

<pre><code>package te.dfs;

import java.io.IOException;
import java.util.List;
import java.util.Locale;

import android.app.Activity;
import android.content.Context;
import android.location.Address;
import android.location.Geocoder;
import android.location.Location;
import android.location.LocationListener;
import android.location.LocationManager;
import android.os.Bundle;
import android.widget.TextView;
import android.widget.Toast;

public class ds extends Activity {
    /** Called when the activity is first created. */
    LocationManager locationManager;
    double lati,longi;
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);

        String location_context = Context.LOCATION_SERVICE;
        locationManager = (LocationManager)getSystemService(location_context);
        testProviders();

    }

    public void testProviders() {
        TextView tv = (TextView)findViewById(R.id.myTextView);
        StringBuilder sb = new StringBuilder("Enabled Providers:");
        List&lt;String&gt; providers = locationManager.getProviders(true);
        for (String provider : providers) 
        {
            locationManager.requestLocationUpdates(provider, 1000, 0,new LocationListener()
            {
                public void onLocationChanged(Location location) {}
                public void onProviderDisabled(String provider){}
                public void onProviderEnabled(String provider){}
                public void onStatusChanged(String provider, int status,
                    Bundle extras){}
            });
            sb.append("\n").append(provider).append(":");
            Location location = locationManager.getLastKnownLocation(provider);
            if (location != null)
            {
                double lat = location.getLatitude();
                double lng = location.getLongitude();
                sb.append(lat).append(",").append(lng);
                lati=lat;
                longi=lng;

                Geocoder gcd = new Geocoder(ds.this, Locale.getDefault());
                List&lt;Address&gt; addresses;
                try {
                    addresses = gcd.getFromLocation(lati, longi, 1);
                    if (addresses.size() &gt; 0) 
                       // System.out.println(addresses.get(0).getLocality());
                        Toast.makeText(ds.this, "hi", 5000).show();
                } catch (IOException e) {

                    Toast.makeText(ds.this, "hi exception", 5000).show();
                    //e.printStackTrace();
                }


            } 
            else 
            {
                sb.append("No Location");
            }
        }
        tv.setText(sb);
        //Toast.makeText(ds.this, String.valueOf(lati)+String.valueOf(longi), 5000).show();
    }

}
</code></pre>
