如何使用 google 地图 api 查找多个位置

how to find multiple locations using google maps api

我想知道我是否可以使用 google 地图 api 查找多个位置。例如,我想使用一个 url 查找餐馆和博物馆 “https://maps.googleapis.com/maps/api/place/textsearch/json?query=restaurants+in+Manhattan&key=”,所以我可以使用相同的 JSON 文件而不是复制文件

没有。如果您搜索 "restaurants or museums in sundancesquare",您的查询将被解释为 "restaurants museums sundancequare",根据我的经验,地图 API不会解析您的查询的含义,它只是从中获取搜索词,并忽略像 "in".

这样的定向词

很难预测您会得到什么结果 - 您可能只会得到与 restaurant and museum and sundancesquare 匹配的匹配项,您可能会混合这两者,并且您可能会得到您意想不到的其他东西:无法保证此调用的结果实际上 餐馆还是博物馆,您可能会得到餐馆供应品或餐厅保险或任何符合该术语的东西。

您应该像 中那样指定类型并使用附近搜索。

但是您仍然无法搜索两种类型,正如 documentation 所说:

Restricts the results to places matching the specified type. Only one type may be specified (if more than one type is provided, all types following the first entry are ignored).

不过我不太明白你的问题。你说你想这样做 "so I can use the same JSON file instead of duplicating files" - 你为什么要为此使用文件?即使您必须这样做,也不能将它们参数化以便更改查询吗?

您可以这样做:https://maps.googleapis.com/maps/api/place/nearbysearch/json?location=37.753,-122.443&radius=1000&type=library&key={YourKey}

这将 return SF 1000 米半径内的所有图书馆。

设置您的 location 参数:Lat-Lng 或地址。

然后设置radius参数:1=1米。

分配type参数:给餐厅。 More on Type

然后您将获得您的餐厅的 JSON 数据。然后对其他类型提出其他请求。不能有超过一种类型。 Place Search。发出多个 HTTP 请求仍会计入您的每日配额,仅供参考。