Recently, I encountered a problem with my Google Map API while trying to retrieve the nearest places.
Here is the code snippet that caused the issue:
var headers = {
'Access-Control-Allow-Origin' : '*',
'Content-Type': 'application/json'
};
var req = {
method: 'GET',
url: 'https://maps.googleapis.com/maps/api/place/nearbysearch/json?location=-33.8670522,151.1957362&radius=500&types=food&name=cruise&key=AIzaSyCLf2OhSgKKOju1hpUBirFtZ-W26zObyVI?sensor=false',
headers: headers
}
$http(req).success(function(d) {
alert(d)
});
This is the error message that was displayed:
XMLHttpRequest cannot load https://maps.googleapis.com/maps/api/place/nearbysearch/json?location=-33.8…=food&name=cruise&key=AIzaSyCLf2OhSgKKOju1hpUBirFtZ-W26zObyVI?sensor=false. No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://localhost:8100' is therefore not allowed access. The response had HTTP status code 405.