0

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.

2
Contributors
6
Replies
7
Views
5 Years
Discussion Span
Last Post by *sharath*
0

Did you set permissions in AndroidManifest?

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

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?

0

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

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.