如何使用 Google Places API 来处理有位置和无位置的搜索请求?

How can I use the Google Places API to handle both search requests with and without a location?

因此,maps.google.com 允许您自行搜索 "sushi bar",并让它在当前地图位置进行搜索。您也可以搜索 "sushi bar in New York, NY",它将忽略当前地图并搜索纽约市。

我如何使用 Google 地点 API 让这两个在一个搜索字段中同时工作?附近和文本搜索似乎都允许一个可选位置,但我不知道如何在输入文本为 "sushi bar in New York, NY."

的情况下使用它

文本搜索允许可选位置。如果您在文本搜索中包含城市,则可能不需要它(这比附近搜索贵 10 倍,因此如果您知道 lat/long,请改用它)

但是根据 API 文档 (https://developers.google.com/places/documentation/search#TextSearchRequests),您可以像这样格式化文本搜索:

https://maps.googleapis.com/maps/api/place/textsearch/xml?location=40.7117,-74.0125&query=sushi+bar+in+New+York,+NY&key=AddYourOwnKeyHere