No way to remove google places autocomplete?

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();

Hiding the Google Autocomplete dropdown suggestions

To hide the suggestions:

 $(".pac-container").css("visibility", "hidden");

To show the suggestions:

 $(".pac-container").css("visibility", "visible");

To trigger hidden or visible based on jquery event(s):

 $("#location").on("keydown click keyup keypress blur change focus", function(){

        if(!$('#geoAutocomplete').is(":checked")){
            $(".pac-container").css("visibility", "hidden");
        }else{
            $(".pac-container").css("visibility", "visible");
        }

    });

Note: I have a checkbox with the id geoAutocomplete for the user to turn the autocomplete on and off.


Even though it's an old post, I would like to answer it now as it would help someone.

Removing the listeners or unbindall() on autocomplete instance will not remove the auto suggestions from occurring and removing the ".pac-container" from DOM is not the clean solution.

The new instance of autocomplete means the input element is hooked with the autocomplete instance and so we have to clear the listeners for input element and not the autocomplete instance.

google.maps.event.clearInstanceListeners(input);