【发布时间】:2017-07-07 13:42:54
【问题描述】:
我正在使用名为“Retrieving Autocomplete Predictions”的 Google Maps API 示例。而且我不知道如何过滤它,所以它只返回美国的地方。我知道如何使用其他示例来做到这一点......
var input = document.getElementById('searchTextField');
var options = {
types: ['(cities)'],
componentRestrictions: {country: 'us'}
};
autocomplete = new google.maps.places.Autocomplete(input, options);
但我似乎不知道如何将它应用到我的示例中。这是我的代码...
function GetAddressPredictions(Search) {
var displaySuggestions = function (predictions, status) {
if (status != google.maps.places.PlacesServiceStatus.OK) {
return;
}
predictions.forEach(function (prediction) {
PredictionArray.push(prediction);
});
};
var service = new google.maps.places.AutocompleteService();
service.getQueryPredictions({input: Search}, displaySuggestions);
}
我试过了,但是没用。
function GetAddressPredictions(Search) {
var displaySuggestions = function (predictions, status) {
if (status != google.maps.places.PlacesServiceStatus.OK) {
return;
}
predictions.forEach(function (prediction) {
PredictionArray.push(prediction);
});
};
var options = {
types: ['(cities)'],
componentRestrictions: {country: 'us'}
};
var service = new google.maps.places.AutocompleteService();
service.getQueryPredictions({input: Search, options}, displaySuggestions);
}
有什么想法吗?谢谢。
【问题讨论】:
标签: javascript google-maps google-maps-api-3 maps