Google 地图 API - 自动完成建议缺少一些 locations/places

Google Maps API - Autocomplete Suggestions are missing some locations/places

我们在 Rails 应用程序中使用 Google 地图的 API,带有 VueJS 前端。

我认为以上任何一项都不重要,因为我已经检查了浏览器中的 URL JSON 响应并且缺少位置。它似乎适用于城市名称、邮政编码 - 但它没有显示与我在 Google 日历中输入位置字段时相同的建议。例如。

请求URL(删除了明显的tokens/auth键):-

https://maps.googleapis.com/maps/api/place/autocomplete/json?types=geocode&input=Ritz%20London

回复:-

{
   "predictions" : [
      {
         "description" : "Ritz Parade, London, UK",
         "matched_substrings" : [
            {
               "length" : 4,
               "offset" : 0
            },
            {
               "length" : 6,
               "offset" : 13
            }
         ],
         "place_id" : "EhdSaXR6IFBhcmFkZSwgTG9uZG9uLCBVSyIuKiwKFAoSCbu6Pcob",
         "reference" : "EhdSaXR6IFBhcmFkZSwgTG9uZG9uLCBVSyIuKiwKFAoSCbu6PcobEnZIEbPVf1MZfE",
         "structured_formatting" : {
            "main_text" : "Ritz Parade",
            "main_text_matched_substrings" : [
               {
                  "length" : 4,
                  "offset" : 0
               }
            ],
            "secondary_text" : "London, UK",
            "secondary_text_matched_substrings" : [
               {
                  "length" : 6,
                  "offset" : 0
               }
            ]
         },
         "terms" : [
            {
               "offset" : 0,
               "value" : "Ritz Parade"
            },
            {
               "offset" : 13,
               "value" : "London"
            },
            {
               "offset" : 21,
               "value" : "UK"
            }
         ],
         "types" : [ "route", "geocode" ]
      }
   ],
   "status" : "OK"
}

这里没有显示实际的伦敦丽兹酒店,但它清楚地显示在我的 Google 日历位置搜索中。

我目前无法访问我们的 API 控制台,但假设这是一个需要在 API 控制台中打开的设置,或者作为附加参数传递到我们的要求?还是我找错地方了?

进行相同的搜索并使用 establishment 作为 types 参数 returns 您可能想要的结果。

根据 types documentation:

establishment instructs the Place Autocomplete service to return only business results.

请求types=establishmenthttps://maps.googleapis.com/maps/api/place/autocomplete/json?types=establishment&input=Ritz%20London&language=en&key=your_api_key_here

{
   "predictions" : [
      {
         "description" : "The Ritz London, Piccadilly, London, UK",
         "matched_substrings" : [
            {
               "length" : 4,
               "offset" : 4
            },
            {
               "length" : 6,
               "offset" : 29
            }
         ],
         "place_id" : "ChIJV8gP0ykFdkgRFEAEHoE1YVk",
         "reference" : "ChIJV8gP0ykFdkgRFEAEHoE1YVk",
         "structured_formatting" : {
            "main_text" : "The Ritz London",
            "main_text_matched_substrings" : [
               {
                  "length" : 4,
                  "offset" : 4
               }
            ],
            "secondary_text" : "Piccadilly, London, UK",
            "secondary_text_matched_substrings" : [
               {
                  "length" : 6,
                  "offset" : 12
               }
            ]
         },
         "terms" : [
            {
               "offset" : 0,
               "value" : "The Ritz London"
            },
            {
               "offset" : 17,
               "value" : "Piccadilly"
            },
            {
               "offset" : 29,
               "value" : "London"
            },
            {
               "offset" : 37,
               "value" : "UK"
            }
         ],
         "types" : [ "lodging", "restaurant", "food", "point_of_interest", "establishment" ]
      },
      {
         "description" : "Ritz, London, UK",
         "matched_substrings" : [
            {
               "length" : 4,
               "offset" : 0
            },
            {
               "length" : 6,
               "offset" : 6
            }
         ],
         "place_id" : "ChIJ1wd5z6gFdkgRUdbMn3pMiKM",
         "reference" : "ChIJ1wd5z6gFdkgRUdbMn3pMiKM",
         "structured_formatting" : {
            "main_text" : "Ritz",
            "main_text_matched_substrings" : [
               {
                  "length" : 4,
                  "offset" : 0
               }
            ],
            "secondary_text" : "London, UK",
            "secondary_text_matched_substrings" : [
               {
                  "length" : 6,
                  "offset" : 0
               }
            ]
         },
         "terms" : [
            {
               "offset" : 0,
               "value" : "Ritz"
            },
            {
               "offset" : 6,
               "value" : "London"
            },
            {
               "offset" : 14,
               "value" : "UK"
            }
         ],
         "types" : [ "laundry", "point_of_interest", "establishment" ]
      },
      {
         "description" : "Ritz London Cigars, Piccadilly, London, UK",
         "matched_substrings" : [
            {
               "length" : 11,
               "offset" : 0
            }
         ],
         "place_id" : "ChIJa_Ih9V8FdkgRfNt8eaSIXuw",
         "reference" : "ChIJa_Ih9V8FdkgRfNt8eaSIXuw",
         "structured_formatting" : {
            "main_text" : "Ritz London Cigars",
            "main_text_matched_substrings" : [
               {
                  "length" : 11,
                  "offset" : 0
               }
            ],
            "secondary_text" : "Piccadilly, London, UK"
         },
         "terms" : [
            {
               "offset" : 0,
               "value" : "Ritz London Cigars"
            },
            {
               "offset" : 20,
               "value" : "Piccadilly"
            },
            {
               "offset" : 32,
               "value" : "London"
            },
            {
               "offset" : 40,
               "value" : "UK"
            }
         ],
         "types" : [ "point_of_interest", "store", "establishment" ]
      },
      {
         "description" : "Hiro Miyoshi at The Ritz London, The Ritz, Piccadilly, London, UK",
         "matched_substrings" : [
            {
               "length" : 11,
               "offset" : 20
            }
         ],
         "place_id" : "ChIJcXuw6tkFdkgR89PgYYTudzU",
         "reference" : "ChIJcXuw6tkFdkgR89PgYYTudzU",
         "structured_formatting" : {
            "main_text" : "Hiro Miyoshi at The Ritz London",
            "main_text_matched_substrings" : [
               {
                  "length" : 11,
                  "offset" : 20
               }
            ],
            "secondary_text" : "The Ritz, Piccadilly, London, UK"
         },
         "terms" : [
            {
               "offset" : 0,
               "value" : "Hiro Miyoshi at The Ritz London"
            },
            {
               "offset" : 33,
               "value" : "The Ritz"
            },
            {
               "offset" : 43,
               "value" : "Piccadilly"
            },
            {
               "offset" : 55,
               "value" : "London"
            },
            {
               "offset" : 63,
               "value" : "UK"
            }
         ],
         "types" : [
            "beauty_salon",
            "hair_care",
            "spa",
            "point_of_interest",
            "store",
            "establishment"
         ]
      },
      {
         "description" : "Ritz Restaurant, King Street, London, UK",
         "matched_substrings" : [
            {
               "length" : 4,
               "offset" : 0
            },
            {
               "length" : 6,
               "offset" : 30
            }
         ],
         "place_id" : "ChIJOVU94EkOdkgRqhr357HTODs",
         "reference" : "ChIJOVU94EkOdkgRqhr357HTODs",
         "structured_formatting" : {
            "main_text" : "Ritz Restaurant",
            "main_text_matched_substrings" : [
               {
                  "length" : 4,
                  "offset" : 0
               }
            ],
            "secondary_text" : "King Street, London, UK",
            "secondary_text_matched_substrings" : [
               {
                  "length" : 6,
                  "offset" : 13
               }
            ]
         },
         "terms" : [
            {
               "offset" : 0,
               "value" : "Ritz Restaurant"
            },
            {
               "offset" : 17,
               "value" : "King Street"
            },
            {
               "offset" : 30,
               "value" : "London"
            },
            {
               "offset" : 38,
               "value" : "UK"
            }
         ],
         "types" : [
            "cafe",
            "restaurant",
            "food",
            "point_of_interest",
            "store",
            "establishment"
         ]
      }
   ],
   "status" : "OK"
}

在同一文档页面上:

If nothing is specified, all types are returned. In general only a single type is allowed. The exception is that you can safely mix the geocode and establishment types, but note that this will have the same effect as specifying no types.

未指定 types 的请求:https://maps.googleapis.com/maps/api/place/autocomplete/json?input=Ritz%20London&language=en&key=your_api_key_here

{
   "predictions" : [
      {
         "description" : "The Ritz London, Piccadilly, London, UK",
         "matched_substrings" : [
            {
               "length" : 4,
               "offset" : 4
            },
            {
               "length" : 6,
               "offset" : 29
            }
         ],
         "place_id" : "ChIJV8gP0ykFdkgRFEAEHoE1YVk",
         "reference" : "ChIJV8gP0ykFdkgRFEAEHoE1YVk",
         "structured_formatting" : {
            "main_text" : "The Ritz London",
            "main_text_matched_substrings" : [
               {
                  "length" : 4,
                  "offset" : 4
               }
            ],
            "secondary_text" : "Piccadilly, London, UK",
            "secondary_text_matched_substrings" : [
               {
                  "length" : 6,
                  "offset" : 12
               }
            ]
         },
         "terms" : [
            {
               "offset" : 0,
               "value" : "The Ritz London"
            },
            {
               "offset" : 17,
               "value" : "Piccadilly"
            },
            {
               "offset" : 29,
               "value" : "London"
            },
            {
               "offset" : 37,
               "value" : "UK"
            }
         ],
         "types" : [ "lodging", "restaurant", "food", "point_of_interest", "establishment" ]
      },
      {
         "description" : "Ritz, London, UK",
         "matched_substrings" : [
            {
               "length" : 4,
               "offset" : 0
            },
            {
               "length" : 6,
               "offset" : 6
            }
         ],
         "place_id" : "ChIJ1wd5z6gFdkgRUdbMn3pMiKM",
         "reference" : "ChIJ1wd5z6gFdkgRUdbMn3pMiKM",
         "structured_formatting" : {
            "main_text" : "Ritz",
            "main_text_matched_substrings" : [
               {
                  "length" : 4,
                  "offset" : 0
               }
            ],
            "secondary_text" : "London, UK",
            "secondary_text_matched_substrings" : [
               {
                  "length" : 6,
                  "offset" : 0
               }
            ]
         },
         "terms" : [
            {
               "offset" : 0,
               "value" : "Ritz"
            },
            {
               "offset" : 6,
               "value" : "London"
            },
            {
               "offset" : 14,
               "value" : "UK"
            }
         ],
         "types" : [ "laundry", "point_of_interest", "establishment" ]
      },
      {
         "description" : "Ritz London Cigars, Piccadilly, London, UK",
         "matched_substrings" : [
            {
               "length" : 11,
               "offset" : 0
            }
         ],
         "place_id" : "ChIJa_Ih9V8FdkgRfNt8eaSIXuw",
         "reference" : "ChIJa_Ih9V8FdkgRfNt8eaSIXuw",
         "structured_formatting" : {
            "main_text" : "Ritz London Cigars",
            "main_text_matched_substrings" : [
               {
                  "length" : 11,
                  "offset" : 0
               }
            ],
            "secondary_text" : "Piccadilly, London, UK"
         },
         "terms" : [
            {
               "offset" : 0,
               "value" : "Ritz London Cigars"
            },
            {
               "offset" : 20,
               "value" : "Piccadilly"
            },
            {
               "offset" : 32,
               "value" : "London"
            },
            {
               "offset" : 40,
               "value" : "UK"
            }
         ],
         "types" : [ "point_of_interest", "store", "establishment" ]
      },
      {
         "description" : "Hiro Miyoshi at The Ritz London, The Ritz, Piccadilly, London, UK",
         "matched_substrings" : [
            {
               "length" : 11,
               "offset" : 20
            }
         ],
         "place_id" : "ChIJcXuw6tkFdkgR89PgYYTudzU",
         "reference" : "ChIJcXuw6tkFdkgR89PgYYTudzU",
         "structured_formatting" : {
            "main_text" : "Hiro Miyoshi at The Ritz London",
            "main_text_matched_substrings" : [
               {
                  "length" : 11,
                  "offset" : 20
               }
            ],
            "secondary_text" : "The Ritz, Piccadilly, London, UK"
         },
         "terms" : [
            {
               "offset" : 0,
               "value" : "Hiro Miyoshi at The Ritz London"
            },
            {
               "offset" : 33,
               "value" : "The Ritz"
            },
            {
               "offset" : 43,
               "value" : "Piccadilly"
            },
            {
               "offset" : 55,
               "value" : "London"
            },
            {
               "offset" : 63,
               "value" : "UK"
            }
         ],
         "types" : [
            "beauty_salon",
            "hair_care",
            "spa",
            "point_of_interest",
            "store",
            "establishment"
         ]
      },
      {
         "description" : "Ritz Parade, London, UK",
         "matched_substrings" : [
            {
               "length" : 4,
               "offset" : 0
            },
            {
               "length" : 6,
               "offset" : 13
            }
         ],
         "place_id" : "EhdSaXR6IFBhcmFkZSwgTG9uZG9uLCBVSyIuKiwKFAoSCbu6PcobEnZIEbPVf1MZfEocEhQKEgnz8xe3Wxt2SBEKsgA5eS6RSQ",
         "reference" : "EhdSaXR6IFBhcmFkZSwgTG9uZG9uLCBVSyIuKiwKFAoSCbu6PcobEnZIEbPVf1MZfEocEhQKEgnz8xe3Wxt2SBEKsgA5eS6RSQ",
         "structured_formatting" : {
            "main_text" : "Ritz Parade",
            "main_text_matched_substrings" : [
               {
                  "length" : 4,
                  "offset" : 0
               }
            ],
            "secondary_text" : "London, UK",
            "secondary_text_matched_substrings" : [
               {
                  "length" : 6,
                  "offset" : 0
               }
            ]
         },
         "terms" : [
            {
               "offset" : 0,
               "value" : "Ritz Parade"
            },
            {
               "offset" : 13,
               "value" : "London"
            },
            {
               "offset" : 21,
               "value" : "UK"
            }
         ],
         "types" : [ "route", "geocode" ]
      }
   ],
   "status" : "OK"
}