如何仅从 PlaceAutocomplete android 获取特定国家/地区的搜索结果?

How to get search result of a Specific country only from PlaceAutocomplete android?

我想要这个问题的解决方案,请建议该怎么做,我只想从 google 的 PlaceAutocomplete 搜索特定国家/地区的结果,我如何设置过滤器以便它只仅显示该国家/地区的结果,例如如果我想要仅适用于印度的搜索结果,该怎么做? PlaceAutocomplete 可以吗?

代码:

try {
        Intent intent = new PlaceAutocomplete.IntentBuilder(PlaceAutocomplete.MODE_OVERLAY).build(activity);
        startActivityForResult(intent, 1);
    } catch (GooglePlayServicesRepairableException e) {
        e.printStackTrace();
    } catch (GooglePlayServicesNotAvailableException e) {
        e.printStackTrace();
    }

如屏幕截图所示,它显示了全球的结果,我只想要特定国家/地区的结果

您可以使用 LatLngBounds 构造方法。这将帮助您限制对矩形区域的搜索(但这不一定会限制对一个国家的搜索,而是该矩形区域中的所有国家)。或者您可以使用 Google Places Web 服务 API,如图 here

更多解释请参考这个回答here

对于当前城市的搜索地点,您必须将 LatLongBounds 设置为 PLaceAutocomplete 之类的。在这里查看我的回答