Android Google Place Picker get city?;
等级包括城市、国家、地址和邮政,但我想 把它们分开,谢谢Android Google Place Picker get city?;,android,google-maps,google-places-api,Android,Google Maps,Google Places Api,等级包括城市、国家、地址和邮政,但我想 把它们分开,谢谢 protected void onActivityResult(int requestCode, int resultCode, Intent data) { if(resultCode==RESULT_OK){ final Place place = PlacePicker.getPlace(this,data); final CharSequence name = place.getN
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();
}
final Place=PlacePicker.getPlace(这个,数据);
Geocoder Geocoder=新的Geocoder(本);
尝试
{
列表地址=geocoder.getFromLocation(place.getLatLng().纬度,place.getLatLng().经度,1);
字符串地址=地址.get(0).getAddressLine(0);
字符串city=addresses.get(0).getAddressLine(1);
//字符串country=addresses.get(0).getAddressLine(2);
}捕获(IOE异常)
{
bottomSheetAddress.setText(“不可用”);
e、 printStackTrace();
}
我已经回答了同样的问题,可能会对您有所帮助。您可以找到它您是否能够获得所需的详细信息?你能接受这个答案吗?Geocoder是Google API插件的一部分,而不是AOSP的一部分。