将Google Places API响应存储在列表中吗?

问题描述 投票:0回答:1

我目前正在一个项目中,我想在该项目上使用Google Places API进行多个“附近搜索”调用,并将结果存储在一个列表中,以便我可以随机选择该列表中的一个位置,以将其显示为标记一张地图。由于某些原因,我在将这些位置保存到列表时遇到了麻烦。有什么想法吗?

预先感谢您,如果这是一个令人困惑或愚蠢的问题!

javascript html api google-places-api
1个回答
0
投票
示例API URL:https://maps.googleapis.com/maps/api/place/nearbysearch/json?location=YOUR_LAT,YOUR_LONG&radius=500&keyword=food&key=YOUR_KEY

您可以在此处找到API的所有可用选项:Nearby Search requests

假设response是Google Maps附近搜索API的返回对象。

const keywords = ['my', 'multiple', 'keyword', 'searches'] let list = [] keywords.forEach(async(keyword) => { await nearbySearchCall(keyword) // This is your nearby place search logic let results = response.results list.push(...results) }) // insert code here for iterating the responses and plotting onto the map.

© www.soinside.com 2019 - 2024. All rights reserved.