Open dbusck opened 6 years ago
First time submitting an issue, please let me know if you need any more information!
Steps to reproduce:
My suggestion is to either.
Plugin.prototype
init
Before:
init: function (id) { var _this = this; $(function () { var fields = { lat: document.getElementById(_this.options.prefix + _this.options.name + '-lat'), lng: document.getElementById(_this.options.prefix + _this.options.name + '-lng'), placeid: document.getElementById(_this.options.prefix + _this.options.name + '-placeid'), } var input = document.getElementById(_this.options.prefix + _this.options.name + '-location'); var options = JSON.parse('{' + _this.options.optionsObject + '}'); var autocomplete = new google.maps.places.Autocomplete(input, options); autocomplete.addListener('place_changed', function () { var place = autocomplete.getPlace(); console.log(place); fields.lat.value = place.geometry.location.lat(); fields.lng.value = place.geometry.location.lng() fields.placeid.value = place.place_id; }); input.addEventListener('change', function(e) { if (!input.value) { fields.lat.value = ''; fields.lng.value = ''; fields.placeid.value = ''; } }); }); }
After:
init: function (id) { var _this = this; var google = window.google; if (!google) { setTimeout(function() { _this.init(); }, 250); } else { $(function () { var fields = { lat: document.getElementById(_this.options.prefix + _this.options.name + '-lat'), lng: document.getElementById(_this.options.prefix + _this.options.name + '-lng'), placeid: document.getElementById(_this.options.prefix + _this.options.name + '-placeid'), } var input = document.getElementById(_this.options.prefix + _this.options.name + '-location'); var options = JSON.parse('{' + _this.options.optionsObject + '}'); var autocomplete = new google.maps.places.Autocomplete(input, options); autocomplete.addListener('place_changed', function () { var place = autocomplete.getPlace(); console.log(place); fields.lat.value = place.geometry.location.lat(); fields.lng.value = place.geometry.location.lng() fields.placeid.value = place.place_id; }); input.addEventListener('change', function(e) { if (!input.value) { fields.lat.value = ''; fields.lng.value = ''; fields.placeid.value = ''; } }); }); } }
First time submitting an issue, please let me know if you need any more information!
Steps to reproduce:
My suggestion is to either.
Plugin.prototype
init
function, which checks if google is defined yet:Before:
After: