Google Maps API web服务应该与GET方法一起使用,而不是POST方法。应该与POST一起使用的唯一web服务是
Geolocation API
。
您应该将代码更改为
var headers = {
'User-Agent': 'Super Agent/0.0.1',
'Content-Type': 'application/x-www-form-urlencoded'
};
// Configure the request
var options = {
url: "https://maps.googleapis.com/maps/api/place/autocomplete/json",
method: 'GET',
headers: headers,
qs: {
key: gkey,
input: input,
types: ['(cities)'],
componentRestrictions: {country: 'IL'}
}
};
// Start the request
request(options, function (error, response, body) {
// returning the body to the frontend
});
我希望这有帮助!