I'm trying to request some information from the Google Places API using Angular 5 but I'm always getting this CORS error:
Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://localhost:4200' is therefore not allowed access.
But when I see the network tab from the developer tools I can see that the http call is returning a 200 status code with the requested information.
This is how I'm calling the Places API:
getAutocompleteSuggestions(location: string, position?: Position): Observable<Object> {
let params = new HttpParams()
.append('input', location)
.append('language', navigator.language)
.append('key', environment.googlePlacesApiKey);
if (position) {
params = params.append('location', `${position.coords.latitude},${position.coords.longitude}`);
}
return this.http.get(GOOGLE_API_URL, { params });
}
And this is the call as seen in the network tab on the developer tools:
Any idea on how to avoid that?