How to put google places api working code under II

2019-07-29 02:54发布

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

0条回答
登录 后发表回答