【发布时间】:2015-10-31 12:00:56
【问题描述】:
(尝试创建jsbin,但它不会加载 Google 库)
加载此版本的 API 库: https://maps.googleapis.com/maps/api/js?v=3.21&libraries=places&callback=onAPILoaded
运行这个 JS:
function runQuery(country) {
var request = {
input: 'london',
componentRestrictions: {country: country},
};
var callback = function(predictions, status) {
if (status != google.maps.places.PlacesServiceStatus.OK) {
alert(status);
return;
}
var resultsString = predictions.reduce(function (prev, current) {
return prev + "\n" + current.description;
}, "RESULTS FOR " + country + "\n--------------\n");
console.log(resultsString);
};
var service = new window.google.maps.places.AutocompleteService();
service.getQueryPredictions(request, callback);
}
// on api loaded...
function onAPILoaded() {
runQuery('uk');
runQuery('ca');
}
得到这个输出
RESULTS FOR uk
--------------
London, United Kingdom
London, ON, Canada
London Borough of Hillingdon, United Kingdom
London Eye, London, United Kingdom
London Bridge, London, United Kingdom
RESULTS FOR ca
--------------
London, United Kingdom
London, ON, Canada
London Borough of Hillingdon, United Kingdom
London Eye, London, United Kingdom
London Bridge, London, United Kingdom
问题在于它看起来不像 componentRestrictions 正在做任何事情 - 无论国家/地区代码如何,结果都是相同的。有任何想法吗?提前致谢。
【问题讨论】:
标签: google-maps google-maps-api-3