【发布时间】:2019-11-05 08:09:20
【问题描述】:
我正在尝试进行 api 调用(Google Places API)。但是我不断收到以下错误
访问 XMLHttpRequest 在 'https://maps.googleapis.com/maps/api/place/findplacefromtext/json?input=Seoul&inputtype=textquery&fields=photos,formatted_address,name,rating,opening_hours,geometry&key=--snip--' 来自原点“http://localhost:8100”已被 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);
});
}
但是,如果我将网址替换为 https://www.reddit.com/r/gifs/top/.json?limit=105sort=hot
它工作正常。为什么呢?我该如何解决?
【问题讨论】:
标签: javascript google-maps ionic-framework google-places-api ionic4