Android Google Places API- 有什么方法可以从 Place 对象获取城市吗?

Android Google Places API- Is there any way to get the city from Place objects?

我正在使用 autocomplete widget of Google Place API for Android and getting a place object, but I am not able to extract the city of it, just only the complete address 作为文本。

显然,Place 接口没有到 return 城市的方法。

城市是地址组件是地方和行政区级别 3,根据此 documentation

有人知道获取 Place 对象所在城市的方法吗?

这是一个 hack,但它确实有效。您可以从 Place 对象中获取纬度和经度,并从 Geocoder 中查找城市。

Geocoder geocoder = new Geocoder(this, Locale.getDefault());
 List<Address> addresses = geocoder.getFromLocation(MyLat, MyLong, 1);
 String cityName = addresses.get(0).getAddressLine(0);
 String stateName = addresses.get(0).getAddressLine(1);
 String countryName = addresses.get(0).getAddressLine(2);