Skip to content

Instantly share code, notes, and snippets.

@lubiluk
Created August 7, 2015 13:31
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save lubiluk/7f3a187041e6797aefb1 to your computer and use it in GitHub Desktop.
Save lubiluk/7f3a187041e6797aefb1 to your computer and use it in GitHub Desktop.
myApp.directive('googleplaceAutocomplete', function () {
return {
restrict: 'A',
require: 'ngModel',
scope: {
googleplaceAutocompletePlace: '=?',
googleplaceAutocomplete: '=',
},
link: function postLink(scope, element, attrs, model) {
var options = scope.googleplaceAutocomplete;
var autocomplete = new google.maps.places.Autocomplete(element[0], options);
google.maps.event.addListener(autocomplete, 'place_changed', function () {
scope.$apply(function () {
scope.googleplaceAutocompletePlace = autocomplete.getPlace();
model.$setViewValue(element.val());
});
});
scope.$on('$destroy', function () {
google.maps.event.clearInstanceListeners(element[0]);
});
}
};
});
@Nezahual
Copy link

Nezahual commented May 10, 2016

Sorry but your modification of Easy AngularJS Directive for Google Places Autocomplete doesn't work. It gives me the following warnings:

@plentini
Copy link

@Nezahual to solve this warnings you have to add your api key and don't use sensor parameter.
https://developers.google.com/maps/documentation/javascript/get-api-key
The problem may be other thing.

<script type="text/javascript" src="http://maps.googleapis.com/maps/api/js?key=yourapikey&libraries=places"></script>

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment