Skip to content Skip to sidebar Skip to footer

How To Get Street Name From Coordinates?

I have the longitude and latitude into two separate EditText I want that when I press a button the street name appears in another EditText. I tried with the Public Address getAddre

Solution 1:

The docs mention the getThoroughfare() method, which may be null. I'd try that first. If null, then I'd try to get something useful from getAddressLine(). It's possible you cannot get a street name for all cases.

Solution 2:

SOLUTION

Geocodergeocoder=newGeocoder(this, Locale.getDefault());

                try {
                    List<Address> addresses = geocoder.getFromLocation(LATITUDE, LONGITUDE, 1);

                    if (addresses != null) {
                        AddressreturnedAddress= addresses.get(0);
                        StringBuilderstrReturnedAddress=newStringBuilder();
                        for (inti=0; i < returnedAddress.getMaxAddressLineIndex(); i++) {
                            strReturnedAddress.append(returnedAddress.getAddressLine(i)).append("");
                        }
                        et_lugar.setText(strReturnedAddress.toString());
                    }
                    else {
                        et_lugar.setText("No Address returned!");
                    }
                } catch (IOException e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                    et_lugar.setText("Canont get Address!");
                }

Solution 3:

first of all, does your phone support location? you need to post the error as well so we know whats the real problem

assuming your phone supports locations, try using the getAdressLine() :

    List<Address> addresses = gc.getFromLocation(latitude, longitude, 1);
    Log.d("=Adress=",addresses.get(0).getAddressLine(0));

the catch here is getting what you want from the list that has the address class structure

Post a Comment for "How To Get Street Name From Coordinates?"