How to put google places api working code under IIFE

微笑、不失礼 提交于 2020-01-05 04:35:33

问题


var calli = (function(){

    var inputbox, geocoder;

function initAutocomplete() {
  geocoder = new google.maps.Geocoder();
  inputbox = new google.maps.places.Autocomplete(
             (document.getElementById('input-box')), {
              types: ['geocode']
             });


  inputbox.addListener('place_changed', fillInAddress);  
}

function fillInAddress() {
  var getplace = inputbox.getPlace();
  codeAddress(document.getElementById('input-box').value);
}

function codeAddress(address) {
   geocoder.geocode({
           'address': address
            }, 
            function(results, status) {
              if (status == 'OK') 
                 { console.log('hi');
                   var senddata = $.get('/myurl',{params}, function (data) {});

               } else {
                       alert( status);
                  }
            });
}

 return (initAutocomplete); 
 })();

calli();

When I use above code without an IIFE it works fine, gives the autocomplete drop down list.
But, when I use it like above, nothing happens, no error, only AuthenticationService gets called, and no call to AutocompletionService.GetPridictions? happens.

Any suggestion as to where I am wrong? Thank you very much.iife

来源:https://stackoverflow.com/questions/55435642/how-to-put-google-places-api-working-code-under-iife

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!