我正在嘗試在Vue JS項(xiàng)目中使用Google Map API。我正在使用兩個Google Maps服務(wù):-第一個是時區(qū)API =>效果很好-第二個是Elevation API =>獲取跨域讀取阻止我驗(yàn)證了郵遞員中的url作品嘗試使用Ajax和vue-resource不使用海拔APIaxios .get(`https://maps.googleapis.com/maps/api/elevation/json?locations=${latitude},${longitude}&key=APIKEY`) .then(response => { console.log(response); return response.result.elevation; }) .catch(error => { console.log(error); });WORKS TIMEZONE APIaxios .get(`https://maps.googleapis.com/maps/api/timezone/json?location=${place.latitude},${place.longitude}×tamp=${moment().unix()}&key=APIKEY`) .then(response => { console.log(response); return response.result.elevation; }) .catch(error => { console.log(error); });結(jié)果是:-從來源' https://test.test '訪問' https://maps.googleapis.com/maps/api/elevation/json?locations=51.49602489999999,-0.17026260000000093&key=APIKEY '處的XMLHttpRequest已被CORS阻止策略:所請求的資源上不存在“ Access-Control-Allow-Origin”標(biāo)頭。和警告:跨域讀取阻止(CORB)阻止了跨域響應(yīng)https://maps.googleapis.com/maps/api/elevation/json?locations=51.49602489999999,-0.17026260000000093&key=APIKEY,MIME類型為application / json
當(dāng)從Vue js通過axios調(diào)用Google Maps海拔API時,如何解決跨域讀取阻止?
躍然一笑
2021-04-28 13:50:02