1

The Place.class include city,country,address and post,but I want to separate them.Thank you !

protected void onActivityResult(int requestCode, int resultCode, Intent data) {

        if(resultCode==RESULT_OK){
        final Place place = PlacePicker.getPlace(this,data);
        final CharSequence name = place.getName();
        final String  address = place.getAddress()+"";
        String attributions = (String) place.getAttributions();
        if (attributions == null) {
            attributions = "";
        }
        et_city.setText(address);
        et_post.setText(address);
        et_street.setText(address);
        }
    }

2 Answers2

3

Try doing this

final Place place = PlacePicker.getPlace(this,data);
Geocoder geocoder = new Geocoder(this);
try
{
    List<Address> addresses = geocoder.getFromLocation(place.getLatLng().latitude,place.getLatLng().longitude, 1);
    String address = addresses.get(0).getAddressLine(0);
    String city = addresses.get(0).getAddressLine(1);
    //String country = addresses.get(0).getAddressLine(2);  

} catch (IOException e)
{
    bottomSheetAddress.setText("Not Available.");
    e.printStackTrace();
}
rakesh kashyap
  • 1,418
  • 22
  • 41
0

I have already answered same question, might help you. You can find it here.

Community
  • 1
  • 1