Tag: google places api

我怎样才能从Google地方获得一系列地点的坐标,然后在结束之后使用结果?

我有一些地名,例如: const places = ['King Square, London', 'Empire State Building', 'Great Wall of China']; 我需要一个新的对象数组,其中包含为地名数组中的每个元素设置的位置,例如: const places = [ { name: 'King Square, London', position: { latitude: …, longitude: … } }, … ]; 我想我必须做这样的事情: const places = []; ['King Square, London', 'Empire State Building', 'Great Wall of China'].forEach(placeName => { axios .get(`https://maps.googleapis.com/maps/api/place/textsearch/json?key=GOOGLE_PLACES_API_KEY&query=${placeName}`) .then(response => […]