我想使用我的提供者向Google Maps API发出请求并检索一些结果,但由于没有任何东西会返回,因此我遇到了麻烦想法我做错了什么。 我对供应商的方法,使一个请求,谷歌:无法使用IONIC 2框架从http请求获取Google Maps API的结果
getClosestMovieTheater(): Observable<Place[]>{
console.log("started request to google.");
let t = this.http
.get('https://maps.googleapis.com/maps/api/place/nearbysearch/json?location=-33.8670522,151.1957362&radius=500&type=restaurant&keyword=cruise&key='MY_API_KEY', { headers: this.getHeaders(), withCredentials: true})
.map(mapAll);
return t;
}
private getHeaders(){
let headers = new Headers();
headers.append('Accept', 'application/json');
return headers;
}
我刨根据我的位置检索最近的电影院,但现在我与谷歌的例子测试它只是为了看看它是否工作。 再就是映射结果的方法:
function toP(r:any): Place{
let p = <Place>({
lng: r.results.geometry.location.lng,
lat: r.results.geometry.location.lat
})
return p;
}
function mapAll(response:Response): Place[]{ return response.json().map(toP); }
任何人都可以请帮助?预先感谢您。
你在哪儿叫'getClosestMovieTheater'?也显示该代码。 – Chrillewoodz
其实我发现这个问题是因为CORS ...问题是我认为它被默认禁用localhost ...你知道任何解决方案,使其在Opera浏览器中启用它吗?谢谢 – Luki