-
Notifications
You must be signed in to change notification settings - Fork 12k
Unable to access google maps api due to CORS #6389
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
Your first link says 'There isn't anything the client application can do about these errors. The server must be configured to accept the application's requests.' |
This is a support question, not necessarily a bug with the CLI, I suggest opening a question on a site like https://stackoverflow.com/ to get some assistance. |
Were you able to solve this issue? |
I ended up using this chrome extension |
Having the same issue ! |
In my experience the plugins worked with http but not with the latest httpClient. Also, configuring the CORS respsonse headers on the server wasn't really an option. So, I created a proxy.conf.json file to act as a proxy server. Read more about this here: https://github.com/angular/angular-cli/blob/master/docs/documentation/stories/proxy.md below is my prox.conf.json file
I placed the proxy.conf.json file right next the the package.json file in the same directory then I modified the start command in the package.json file like below
now, the http call from my app component is as follows
Lastly to run my app, I'd have to use npm start or ng serve --proxy-config proxy.conf.json |
I've spent the last few days trying to find the cleanest solution for this with not much luck. Google do offer a client-side JavaScript library. But to use it, you have to hard-code a script file in I also found that, Google have deprecated Instead, the only real solution I could find was to set up a super-simple NodeJS/Express backend which is configured correctly for CORS and acts as a proxy between your Ionic application and the Google API. It was the first time I ever tried Node and it wasn't too difficult to set this up. I wrote a guide here. and also created a sample Git repo here. |
Still facing the same problem, one year later. |
This issue has been automatically locked due to inactivity. Read more about our automatic conversation locking policy. This action has been performed automatically by a bot. |
Bug Report or Feature Request (mark with an
x
)Versions.
@angular/cli: 1.0.4
node: 6.10.2
os: win32 x64
@angular/animations: 4.1.1
@angular/common: 4.1.1
@angular/compiler: 4.1.1
@angular/compiler-cli: 4.1.1
@angular/core: 4.1.1
@angular/forms: 4.1.1
@angular/http: 4.1.1
@angular/platform-browser: 4.1.1
@angular/platform-browser-dynamic: 4.1.1
@angular/platform-server: 4.1.1
@angular/router: 4.1.1
@angular/cli: 1.0.4
Repro steps.
const serviceURL = 'https://maps.googleapis.com/maps/api/place/textsearch/json?query=' + address + '&key=MyAPIKey'; return this._http.get(serviceURL) .map((response: Response) => response.json()) .catch(error => { console.log(error); return Observable.throw('error'); });
The log given by the failure.
XMLHttpRequest cannot load https://maps.googleapis.com/maps/api/place/textsearch/json?query=16%20B%20R…0%20PARIS%2020%20Ile-de-France&key=... No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://localhost:4200' is therefore not allowed access.
Desired functionality.
The header 'Access-Control-Allow-Origin' added in #2872 does not seem to work.
MRHarrison@8d50a27
Mention any other details that might be useful.
I'm having this problem on any browser, and i have to use a Google chrome extention to get rid of it.
https://chrome.google.com/webstore/detail/allow-control-allow-origi/nlfbmbojpeacfghkpbjhddihlkkiljbi
I tried changing my @angular/cli version in the devDependencies to use the version 1.0.4, but nothing changes.
I printed the serviceURL to try it in postman and in my browser and i don't have any errors, the json response from the api shows up perfectly.
You can get a free API key here if you want to try : https://developers.google.com/places/web-service/get-api-key?hl=fr
The text was updated successfully, but these errors were encountered: