【问题标题】:Android Google Places API- Is there any way to get the city from Place objects?Android Google Places API-有没有办法从 Place 对象中获取城市?
【发布时间】:2017-02-20 19:28:20
【问题描述】:
【问题讨论】:
标签:
android
google-places-api
google-places
【解决方案1】:
这是一个 hack,但它有效。您可以从 Place 对象中获取 lat 和 lng,然后从地理编码器中找到城市。
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);