【问题标题】:Limit Android Google Places API to search only given area将 Android Google Places API 限制为仅搜索给定区域
【发布时间】:2018-03-13 08:14:27
【问题描述】:

我正在使用 Android Google Places API 来自动完成街道和地址。问题是它提供了来自整个国家的所有街道。当然,我添加了边界来限制搜索位置,但它不能正常工作 - 它只给出优先级,所以换句话说,最好的结果会在列表中更高,仅此而已

所以代码:

       AutocompleteFilter typeFilter = new AutocompleteFilter.Builder()
                .setTypeFilter(AutocompleteFilter.TYPE_FILTER_ADDRESS)
                .setCountry("RU")
                .build();

        Intent intent =
                new PlaceAutocomplete.IntentBuilder(PlaceAutocomplete.MODE_OVERLAY)
                        .zzih(searchString) //that is for passing search string from toolbar
                        .setFilter(typeFilter)
                        .setBoundsBias(city.getBounds())
                        .build(this);

简而言之,问题是: 当我输入诸如“Lenina Street”之类的搜索时,我看到很多无用的结果超出了.setBoundsBias(city.getBounds()) 中设置的范围。想象一下,几乎每个地方都有类似“Lenina Street”的东西!

如何解决问题并限制搜索结果?

附言

  1. 我知道我可以使用Google Places Web API 或GeoDataApi.getAutocompletePredictions() 并手动过滤结果, 但这意味着我也必须手动编写 UI,我不想这样做 做。 罢工> 那比我想象的还要糟糕。即使我从 Web API 或通过 GeoDataApi 获得结果,我也只有不包含坐标的预测,只有 placeId。因此,如果我想通过坐标过滤预测,我必须请求 每个 placeId。换句话说,如果我有 20 个地点,我将不得不再执行 20 次请求才能找到坐标。
  2. 我还可以在searchString 中添加城市名称,这会使结果更好(但一点也不),但它会使地址的书写不清楚并且会发生城市名称,所以它也不是很好的解决方案。

【问题讨论】:

    标签: java android google-maps google-places-api


    【解决方案1】:

    恐怕 Android 的 Places API 还不支持严格限制。 Google 问题跟踪器中有一个功能请求来实现这一点:

    https://issuetracker.google.com/issues/38188994

    欢迎对此功能请求加注星标以添加您的投票并订阅来自 Google 的通知。

    与此同时,解决方法可能是使用支持strict bounds 的 Places API Web 服务并手动实现 UI。

    更新

    功能请求已被 Google 标记为已修复。查看 https://stackoverflow.com/a/50134855/5140781,它展示了如何在 Places API for Android 中应用严格的界限。

    【讨论】:

    • 嗯,是的,看起来它现在是唯一的选择。严格限制仅适用于半径,但总比没有好。
    猜你喜欢
    • 2016-01-25
    • 2016-04-02
    • 1970-01-01
    • 2016-06-22
    • 1970-01-01
    • 1970-01-01
    • 2017-08-05
    • 2012-04-12
    • 1970-01-01
    相关资源
    最近更新 更多