我一直在尝试使用Google Places api返回仅限于某个国家/地区(在我的情况下是美国)的自动填充结果,但该服务似乎没有使用componentRestriction属性.我没有发现其他人有这个问题,所以我认为这是我的代码的问题.此外,我正在使用角度的应用程序,但我看不出这将如何影响Web服务.
这基本上就是我所拥有的:
HTML:
<input ng-model="query" ng-keyup="getPredictions(query)">
Run Code Online (Sandbox Code Playgroud)
JS:
var autoComplete = new google.maps.places.AutocompleteService();
$scope.getPredictions(query){
var searchObj = {
input: query,
componentRestrictions: {country: 'us'},
types: '(cities)'
};
autoComplete.getQueryPredictions(searchObj, function(predictions, status) {
//...
$scope.response = predictions;
});
};
Run Code Online (Sandbox Code Playgroud)
'types'过滤器正在运行,但componentRestrictions不是.
我还设置了一个小提琴来演示:http: //jsfiddle.net/jdalton308/cLtyv803/7/
谢谢你的帮助.
小智 5
根据文档 getQueryPredictions()接受QueryAutocompletionRequest对象 - 它根本没有componentRestrictions属性.
所以如果你想使用componentRestrictions你需要使用getPlacePredictions()接受AutocompletionRequest对象的方法.
这应该工作:
autoComplete.getPlacePredictions(searchObj, function(predictions, status) {
//...
$scope.response = predictions;
});
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
1806 次 |
| 最近记录: |