diff --git a/bower.json b/bower.json index a002255..6dab9da 100644 --- a/bower.json +++ b/bower.json @@ -1,15 +1,15 @@ { "name": "angular-google-places-autocomplete", - "version": "0.2.7", + "version": "0.2.9", "main": [ "./src/autocomplete.js", "./src/autocomplete.css" ], "dependencies": { - "angular": "^1.2.x" + "angular": "^1.3.x" }, "devDependencies": { - "angular-mocks": "^1.2.x" + "angular-mocks": "^1.3.x" }, "ignore": [] } diff --git a/package.json b/package.json index 8cbe23b..f58d2e6 100644 --- a/package.json +++ b/package.json @@ -1,9 +1,9 @@ { "name": "angular-google-places-autocomplete", - "version": "0.2.7", + "version": "0.2.9", "repository": { "type": "git", - "url": "http://github.com/kuhnza/angular-google-places-autocomplete.git" + "url": "http://github.com/josh3io/angular-google-places-autocomplete.git" }, "dependencies": { "grunt-contrib-cssmin": "^0.10.0" diff --git a/src/autocomplete.js b/src/autocomplete.js index 6b4d27d..907397f 100644 --- a/src/autocomplete.js +++ b/src/autocomplete.js @@ -56,6 +56,7 @@ angular.module('google.places', []) $scope.predictions = []; $scope.input = element; $scope.options = $scope.options || {}; + $scope.min_length = $scope.min_length || 3; initAutocompleteDrawer(); initEvents(); @@ -164,7 +165,7 @@ angular.module('google.places', []) }); }); } else { - placesService.getDetails({ placeId: prediction.place_id }, function (place, status) { + placesService.getDetails({ reference: prediction.reference }, function (place, status) { if (status == google.maps.places.PlacesServiceStatus.OK) { $scope.$apply(function () { $scope.model = place; @@ -187,27 +188,32 @@ angular.module('google.places', []) $scope.query = viewValue; - request = angular.extend({ input: viewValue }, $scope.options); - autocompleteService.getPlacePredictions(request, function (predictions, status) { - $scope.$apply(function () { - var customPlacePredictions; + // require a minimum number of letters entered before making requests to google + if ($scope.min_length > 0 && viewValue.match("[a-zA-Z]{"+$scope.min_length+"}")) { + request = angular.extend({ input: viewValue }, $scope.options); + autocompleteService.getPlacePredictions(request, function (predictions, status) { + $scope.$apply(function () { + var customPlacePredictions; - clearPredictions(); + clearPredictions(); - if ($scope.customPlaces) { - customPlacePredictions = getCustomPlacePredictions($scope.query); - $scope.predictions.push.apply($scope.predictions, customPlacePredictions); - } + if ($scope.customPlaces) { + customPlacePredictions = getCustomPlacePredictions($scope.query); + $scope.predictions.push.apply($scope.predictions, customPlacePredictions); + } - if (status == google.maps.places.PlacesServiceStatus.OK) { - $scope.predictions.push.apply($scope.predictions, predictions); - } + if (status == google.maps.places.PlacesServiceStatus.OK) { + $scope.predictions.push.apply($scope.predictions, predictions); + } - if ($scope.predictions.length > 5) { - $scope.predictions.length = 5; // trim predictions down to size - } + if ($scope.predictions.length > 5) { + $scope.predictions.length = 5; // trim predictions down to size + } + }); }); - }); + } else { + clearPredictions(); + } if ($scope.forceSelection) { return controller.$modelValue;