【发布时间】:2018-05-28 03:06:33
【问题描述】:
我正在尝试调用 google api 从 ember js 获取地点建议。如下:这是服务模块
fetch(){
let url=`https://maps.googleapis.com/maps/api/place/autocomplete/json?input=IL&types=geocode&key=API_KEY`
return Ember.RSVP.resolve(Ember.$.ajax(url,{
method: 'GET'
}))
.then(
(response)=>{
console.log("google suggested places:",response);
return response;
})
*上面的 url 当与 API_KEY 一起提供并粘贴到浏览器中时,会返回一个带有建议位置的 JSON 响应。
另外,我在开发人员工具的 newtwork 选项卡中看到 JSON 响应,但 .then 无法捕获该响应,并在控制台中打印为未定义的响应。
参考:https://developers.google.com/places/web-service/autocomplete#place_autocomplete_results
在控制台中我看到“无法加载https://maps.googleapis.com/maps/api/place/autocomplete/json?input=IL&types=geocode&key=API_KEY:请求的资源上不存在'Access-control-Allow_origin'标头。因此不允许访问源'http://localhost:4200'。
我做错了什么?
【问题讨论】:
标签: javascript ajax google-maps-api-3 ember.js autocomplete