UNPKG

@alvarosacari/vuetify-google-autocomplete

Version:

A Vuetify ready Vue.jS component to Google Places Autocomplete

1 lines 1.65 kB
var _typeof=typeof Symbol==='function'&&typeof Symbol.iterator==='symbol'?function(obj){return typeof obj}:function(obj){return obj&&typeof Symbol==='function'&&obj.constructor===Symbol&&obj!==Symbol.prototype?'symbol':typeof obj};var loadGoogleMaps=function loadGoogleMaps(apiKey,version,language){try{if(typeof window==='undefined'||typeof document==='undefined'){return}if(_typeof(window.google)==='object'&&_typeof(window.google.maps)==='object'){if(_typeof(window.google.maps.places)==='object'){return}throw new Error('Google is already loaded, but does not contain the places API.')}if(!window.vgaMapState.initMap){var googleMapScript=document.createElement('SCRIPT');var options={};if(typeof apiKey==='string'){options.key=apiKey}else if((typeof apiKey==='undefined'?'undefined':_typeof(apiKey))==='object'){Object.keys(apiKey).forEach(function(key){options[key]=apiKey[key]})}else{throw new Error('apiKey should either be a string or an object')}options.libraries='places';options.callback='initVGAMaps';var parameters=Object.keys(options).map(function(key){return encodeURIComponent(key)+'='+encodeURIComponent(options[key])}).join('&');var url='https://maps.googleapis.com/maps/api/js?'+parameters;if(version){url=url+'&v='+version}if(language){url=url+'&language='+language}googleMapScript.setAttribute('src',url);googleMapScript.setAttribute('async','');googleMapScript.setAttribute('defer','');document.body.appendChild(googleMapScript)}else{throw new Error('Vuetify google autocomplete loaded multiple times.')}}catch(exception){throw new Error('Vuetify google autocomplete load error: ',exception)}};export default loadGoogleMaps;