gpt4 book ai didi

android - Google Place Picker 获取城市?

转载 作者:行者123 更新时间:2023-11-29 17:15:59 25 4
gpt4 key购买 nike

Place.class包括city,country,address和post,但是我想分开他们。谢谢!

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);
}
}

最佳答案

尝试这样做

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();
}

关于android - Google Place Picker 获取城市?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39010189/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com