Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

No way to remove google places autocomplete?

var autocomplete = new google.maps.places.Autocomplete(input, {
  types:  ['geocode']
});

How do I remove it now?

There's "autocomplete.unbindAll()" function but it doesn't remove the HTML for the dropdown box. I have a page that does a lot of ajaxy stuff and because of this dropdown boxes keep being added even tho there's only one autocomplete at a given time on the page :|

like image 905
thelolcat Avatar asked Oct 10 '15 01:10

thelolcat


1 Answers

Assuming this is how things have been initialised

var autocomplete = new google.maps.places.Autocomplete(input, {types: ['geocode']});
var autocompleteLsr = google.maps.event.addListener(autocomplete, 'place_changed', function() { ... });

google maps APIs also provide removeListener and clearInstanceListeners for removal as well. https://developers.google.com/maps/documentation/javascript/reference#event

also as an optional step, you should remove this $(".pac-container") as well

google.maps.event.removeListener(autocompleteLsr);
google.maps.event.clearInstanceListeners(autocomplete);
$(".pac-container").remove();
like image 134
Prabhu Avatar answered Sep 29 '22 23:09

Prabhu