【问题标题】:Android: Google Place API queryAutoComplete delivers ZERO_RESULTS on API 17 - API 19Android:Google Place API queryAutoComplete 在 API 17 - API 19 上提供 ZERO_RESULTS
【发布时间】:2017-01-17 09:41:20
【问题描述】:

以下请求在 web 和 android API 17+ 中运行良好:

搜索字符串:Bruņinieku ie

搜索网址:https://maps.googleapis.com/maps/api/place/queryautocomplete/json?input=Bruņinieku%20ie&key=xxx

搜索结果:

{
   "predictions" : [
      {
         "description" : "Bruņinieku iela, Rīga, Latvija",
         "id" : "6904e5bf90ff4e34b179aba2e28643efc9007017",
         "matched_substrings" : [
            {
               "length" : 13,
               "offset" : 0
            }
         ],
    ...

现在,如果我在末尾添加另一个字母,该请求在 web 和 android API 21+ 中仍然可以正常工作,但在 API 17 - API 19 中则不行:

搜索字符串:Bruņinieku iel

搜索网址:https://maps.googleapis.com/maps/api/place/queryautocomplete/json?input=Bruņinieku%20iel&key=xxx

搜索结果(Web 和 API 21+):

{
   "predictions" : [
      {
         "description" : "Bruņinieku iela, Rīga, Latvija",
         "id" : "6904e5bf90ff4e34b179aba2e28643efc9007017",
         "matched_substrings" : [
            {
               "length" : 15,
               "offset" : 0
            }
         ],
    ...

搜索结果(API 17 - API 19):

{
    "predictions": [],
    "status": "ZERO_RESULTS"
}

为什么?!完全没有意义!起初我认为这可能是位置、半径或语言,所以删除了这些 - 仍然是同样的问题。这不应该发生,但它发生了。

【问题讨论】:

    标签: android google-places-api nativescript


    【解决方案1】:

    Greeeat,浪费了半天时间。事实证明,旧 API 不会自动将未知符号(例如 ņ)转换为 utf-8。您必须使用encodeURIComponent(search_string) 自己完成,这会导致 url:

    https://maps.googleapis.com/maps/api/place/queryautocomplete/json?input=Bru%C5%86inieku%20iel&key=xxx

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2020-03-05
      • 1970-01-01
      • 2015-07-24
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多