Android:Google 地点 API queryAutoComplete 在 API 17 - API 19 交付 ZERO_RESULTS

Android: Google Place API queryAutoComplete delivers ZERO_RESULTS on API 17 - API 19

以下请求在网络和 android API 17+:

中工作正常

搜索字符串:Bruņinieku ie

搜索url: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
            }
         ],
    ...

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

搜索字符串:Bruņinieku iel

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

搜索结果(网络和 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"
}

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

Greeeeeeat,浪费了半天。事实证明,旧的 API 不会自动将未知符号(例如 ņ)转换为 utf-8。你必须自己用 encodeURIComponent(search_string) 来做,这会导致 url:

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