小编Joe*_*ton的帖子

限制Google将.AutocompleteService()限制为Angular中的国家/地区

我一直在尝试使用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/

谢谢你的帮助.

google-places-api

5
推荐指数
1
解决办法
1806
查看次数

标签 统计

google-places-api ×1