0

ユーザーがフィールドに簡単に入力できるように、Google Places API を使用して提案を取得する入力フィールドを作成したいと考えています。

MEAN.js を使用していますが、Angular コントローラーを使用して情報を取得するのに問題があります。

// Get places
$scope.getPlaces = function(val) {
    return $http.jsonp('https://maps.googleapis.com/maps/api/place/autocomplete/json?callback=JSON_CALLBACK', {
        params: {
            input: val,
            types: '(regions)',
            language: 'en',
            key: 'AIzaSyADMplvJfIzKFslb5KfOdZbCKK2SIYVl-E'
        }
    }).then(function(response){
            var places = [];
            angular.forEach(response.predictions, function(item){
                places.push(item.description);
            });
       return places;
    });
};

ビューは、先行入力コンポーネントを使用して自動提案を取得しようとします。

<div class="form-group">
    <input type="text" id="location" name="location" class="form-control" ng-model="asyncSelected" typeahead="place for place in getPlaces($viewValue)" typeahead-loading="loadingPlaces" placeholder="Location">
</div>

コンソールを確認すると、リクエストは 200 OK で返されますが、コンソールにエラーが表示されます。

キャッチされていない SyntaxError: 予期しないトークン:

http jsonp リクエストの何が問題になっていますか? どうすれば修正できますか?

ありがとう乾杯マウリツィオ

4

0 に答える 0