Search code examples
androidgoogle-geocoder

Geolocation in Android throwing exception when I search for the city (or anything rather than country name) works fine with country names


When I search by country name, it works perfect, but when I search for the City or places, app crashes. Here is the code:

EditText location_tf = (EditText)findViewById(R.id.TFaddress);
        String location = location_tf.getText().toString();
        //Toast.makeText(this, location, Toast.LENGTH_SHORT).show();

        Geocoder gc = new Geocoder(this);
        List<Address> list = gc.getFromLocationName(location, 1);
        Address add = list.get(0);
        String locality = add.getLocality();
        Toast.makeText(this, locality, Toast.LENGTH_SHORT).show();

        double lat = add.getLatitude();
        double lng = add.getLongitude();

        gotoLocation(lat, lng, 4);

Solution

  • thanks for the help, I found your answers help. My problem is solved, I was testing app on MIUI Chinese ROM, after installing MIUI international ROM, my code is working like a charm.

    Thank you.