Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/google-maps/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript Google Places API(但不是Reddit)上的CORS错误_Javascript_Google Maps_Ionic Framework_Google Places Api_Ionic4 - Fatal编程技术网

Javascript Google Places API(但不是Reddit)上的CORS错误

Javascript Google Places API(但不是Reddit)上的CORS错误,javascript,google-maps,ionic-framework,google-places-api,ionic4,Javascript,Google Maps,Ionic Framework,Google Places Api,Ionic4,我正在尝试进行api调用(GooglePlacesAPI)。然而,我不断得到以下错误 访问位于的XMLHttpRequest '' 来自源“”已被CORS策略阻止: 请求的服务器上不存在“Access Control Allow Origin”标头 资源 使用以下代码: getRemoteData() { this.http .get( "https://maps.googleapis.com/maps/api/place/findplacefromte

我正在尝试进行api调用(GooglePlacesAPI)。然而,我不断得到以下错误

访问位于的XMLHttpRequest '' 来自源“”已被CORS策略阻止: 请求的服务器上不存在“Access Control Allow Origin”标头 资源

使用以下代码:

  getRemoteData() {
    this.http

      .get(
        "https://maps.googleapis.com/maps/api/place/findplacefromtext/json?input=Seoul&inputtype=textquery&fields=photos,formatted_address,name,rating,opening_hours,geometry&key=--snip--"
      )
      .map(res => res)
      .subscribe(data => {
        console.log(data);
      });
  }
但是如果我将url替换为
https://www.reddit.com/r/gifs/top/.json?limit=105sort=hot


它很好用。为什么会这样?我如何解决它?

这是另一个问题的重复:

这是因为您使用的api不适合服务器使用

CORS策略保护服务器的用户,防止浏览器使用用户凭据向服务器发送未经授权的请求