i am using the following code to get the latitude and longitude values of a particular area.

public class MainActivity extends Activity {

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        List<Address> foundGeocode = null;
        /* find the addresses  by using getFromLocationName() method with the given address*/
        try {
            foundGeocode = new Geocoder(this).getFromLocationName("Hyderabad", 1);
            foundGeocode.get(0).getLatitude(); //getting latitude
             foundGeocode.get(0).getLongitude();//getting longitude
             Toast.makeText(this, ""+ foundGeocode.get(0).getLatitude()+"   "+foundGeocode.get(0).getLongitude(), 20).show();

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

    }

But the catch block is being executed instead of getting the latitude and longitude values.
Can any one help me out.

I sent values to emulator using the ddms view and later tried to work out this code.
i am getting the following warning.

07-13 09:05:13.390: W/System.err(368): java.io.IOException: Service not Available

thanks in advance.

Recommended Answers

All 6 Replies

Did you set permissions in AndroidManifest?

<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.INTERNET" />

yes i used them and also included fine location.

If you are using smulator prior 4.0 you will get this. Quite lot of similar based question on stackoverflow. Are you using real device or some emulator?

am using an emulator.

Well then you have to use anything above 4.0. Be aware emulators at this stage are very slow if you do not set them right

thank you

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.