Skip to Content


Actually queries the Google Maps address API.

JavaScript February 7, 2021


This function runs automatically, so it is not called manually. Is this incorrect?


Demo file is missing! Please report this error.

Additional Notes

Instead of calling this function directly, please use nebulaAddressAutocomplete() so that the Google Maps library can be loaded as needed.

Was this page helpful? Yes No

    A feedback message is required to submit this form.

    Please check that you have entered a valid email address.

    Enter your email address if you would like a response.

    Thank you for your feedback!

    Source File

    Located in /assets/js/modules/location.js on line 34.

    No Hooks

    This function does not have any filters or actions available. Request one?
    nebula.googleAddressAutocompleteCallback = function(autocompleteInput, uniqueID = 'unnamed'){
        window[uniqueID] = new google.maps.places.Autocomplete(
            {types: ['geocode']} //Restrict the search to geographical location types
        google.maps.event.addListener(window[uniqueID], 'place_changed', function(){ //When the user selects an address from the dropdown, populate the address fields in the form.
            let place = window[uniqueID].getPlace(); //Get the place details from the window[uniqueID] object.
            let simplePlace = nebula.sanitizeGooglePlaceData(place, uniqueID);
            let thisEvent = {
                event_name: 'autocomplete_address',
                event_category: 'Contact',
                event_action: 'Autocomplete Address',
                event_label: + ', ' + simplePlace.state.abbr + ' ' +,
                place: place,
                simple_place: simplePlace
            nebula.dom.document.trigger('nebula_address_selected', [place, simplePlace, jQuery(autocompleteInput)]);
            nebula.dom.document.trigger('nebula_event', thisEvent);
            gtag('event', thisEvent.event_name, nebula.gaEventObject(thisEvent));
            nebula.crm('identify', {
                street_number: simplePlace.street.number,
                street_full: simplePlace.street.full,
                county: simplePlace.county,
                address: simplePlace.street.full + ', ' + + ', ' + simplePlace.state.abbr + ' ' +
        jQuery(autocompleteInput).on('focus', function(){
            if ( === 'https' && navigator.geolocation ){
                navigator.geolocation.getCurrentPosition(function(position){ //Bias to the user's geographical location.
                    let geolocation = new google.maps.LatLng(position.coords.latitude, position.coords.longitude);
                    let circle = new google.maps.Circle({
                        center: geolocation,
                        radius: position.coords.accuracy
        }).on('keydown', function(e){
            if ( e.key === 'Enter' && jQuery('.pac-container:visible').length ){ //Prevent form submission when enter key is pressed while the "Places Autocomplete" container is visbile
                return false;
        if ( autocompleteInput === '#address-autocomplete' ){
            nebula.dom.document.on('nebula_address_selected', function(){
                //do any default stuff here.


    To override or disable this JavaScript function, simply redeclare it with the exact same function name. Remember: Some functionality is conditionally loaded via dynamic imports, so if your function is not overriding properly, try listening for a DOM event (described below).


    For non-module import functions:

    nebula.googleAddressAutocompleteCallback = function(){
        //Write your own code here, leave it blank, or return false.

    For dynamically imported module function overrides:

    jQuery(window).on('load', function(){
        nebula.googleAddressAutocompleteCallback = function(){
            //Write your own code here, leave it blank, or return false.

    Custom Nebula DOM events do also exist, so you could also try the following if the Window Load listener does not work:

    jQuery(document).on('nebula_module_loaded', function(module){
        //Note that the module variable is also available to know which module specifically was imported
        if ( typeof nebula.googleAddressAutocompleteCallback === 'function' ){
            nebula.googleAddressAutocompleteCallback = function(){
                //Write your own code here, leave it blank, or return false.