I'm trying to use Google Places' API to get a list of cities to display. I was trying to use the Autocomplete feature to get a JSON that I could then parse. But I'm getting the following error:
Failed to load
https://maps.googleapis.com/maps/api/place/autocomplete/json?
input=New&types=(cities)&key=AIzaSyBVgF-ywjsdsWx6JMZNR0UlUL8q67wM5m8:
No 'Access-Control-Allow-Origin' header is present on the requested
resource. Origin 'http://localhost:4200' is therefore not allowed
access.
I have the following as my API request:
searchCities(searchTerm: String) {
const url =
'https://maps.googleapis.com/maps/api/place/autocomplete/json?
input=' + searchTerm +
'&types=(cities)&key=AIzaSyBVgF-ywjsdsWx6JMZNR0UlUL8q67wM5m8';
return this.http.get(url)
.map((response: Response) => {
return response.json();
});
}
How can I resolve this?