【问题标题】: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 Place API 的 autocomplete widget 并获取一个地点对象,但我无法提取它的城市,只能提取 complete address 作为文本。

显然Place接口没有返回城市的方法。

根据documentation,城市是地址组成部分是地方和行政区域级别 3。

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

【问题讨论】:

    标签: 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);
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-05-26
      • 2019-01-27
      • 1970-01-01
      • 1970-01-01
      • 2015-06-29
      • 1970-01-01
      相关资源
      最近更新 更多