Google Places API - 启用CORS - Ionic 2 + Angular 2

时间:2016-10-31 03:34:55

标签: angular typescript ionic2 wkwebview

我正在使用Http对象从Google Places API请求数据。它正常工作,但安装WkWebView插件后,我遇到了CORS问题。

有没有办法在没有服务器的情况下启用cors?或者也许我可以使用jsonp?如何做的任何例子?

这是我的代码:

import { Injectable } from '@angular/core';
import { Http } from '@angular/http';
import 'rxjs/add/operator/map';

@Injectable()
export class PlacesService {

  // Geolocation object
    locator: any = null;

  constructor(public http: Http) {}

  search(place: string) {

    console.log('searchPlace', place, encodeURIComponent(place));

    return new Promise(resolve => {

      this.http.get('https://maps.googleapis.com/maps/api/place/textsearch/json?key=MYAPIKEY&query=' + encodeURIComponent(place))
      .map( res => res.json() )
      .subscribe( data => {
        resolve(data);
      });

    }); // Promise
  }
}

谢谢!

0 个答案:

没有答案