有什么办法可以通过Google API获取Google地方半径数据

时间:2019-05-10 07:54:32

标签: angular http google-maps-api-3 google-api cors

我正在使用Google API获取基于半径的地址列表。但是,当我通过HTTP请求调用Google API时,出现以下CORS错误

Access to XMLHttpRequest at 'https://maps.googleapis.com/maps/api/place/details/json?placeid=ChIJwXz9f39xhlQRT3qxXAPDlbU&fields=name,rating,geometry,opening_hours&key=AIzaSyDChYJgIQwTvmtM1LnlBNAKVt891kk5BNg' from origin 'http://localhost:4200' has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource.

我尝试使用以下JavaScript代码,还尝试使用角度HTTP获取请求。

<script src="https://apis.google.com/js/api.js"></script>

var xhr = new XMLHttpRequest();
xhr.open('GET',
  'https://maps.googleapis.com/maps/api/place/details/json?placeid=ChIJwXz9f39xhlQRT3qxXAPDlbU&fields=name,rating,geometry,opening_hours&key=<API KEY>');

xhr.send();

0 个答案:

没有答案