How can I hide the message ‘Oops! Something went wrong’ when an invalid Google Maps API key is supplied? Additionally, how do I capture errors when an invalid Google Maps API key is provided and display the error in an alert message?
hdr_loadGoogleMap: function() {
var me = this,
vFormPanel = me.getFormPanel(),
vFldValues = vFormPanel.getFldValues(['install_gmapikey','install_gmapid','install_gmapcoor','install_gmaptype']),
vContainer = vFormPanel.down('container[hostCmpId=mapContainer]'),
vLat,
vLng,
vGmapcoor = vFldValues['install_gmapcoor'].split(','),
vGMapTypes = {
'map': 'roadmap',
'satellite': 'satellite',
'terrain': 'terrain',
'labels': 'hybrid'
};
vLanguageCode ='en';
Ext.Loader.loadScript({
url: 'https://maps.googleapis.com/maps/api/js?key=inavlidkey&v=3.55&language='+vLanguageCode,
onLoad: function () {
me.hdr_gmap = Ext.create('Ext.panel.Panel', {
layout: 'fit',
header: false,
border: false,
itemId: 'map',
style: 'padding: 0; border-width: 0;',
draggable: false,
height: 290,
width: 350,
items: [{
xtype: 'uxgmappanel',
useCurrentLocation: true,
center: {
lat: vLat,
lng: vLng
},
mapOptions: {
zoom: 14,
mapTypeId: vGMapTypes[(vFldValues['install_gmaptype']) ? vFldValues['install_gmaptype'].toLowerCase(): 'map'],
mapId: vFldValues['install_gmapid']
}
}]
});
vContainer.add(me.hdr_gmap);
}
});
window.gm_authFailure = function() {
var vDelayedTask = new Ext.util.DelayedTask(function() {
alert('MSG_ERR_JS_INAVLID_GAPIKEY_GMAPID');
});
vDelayedTask.delay(300);
};
}
2
Answers
Thanks for the response. I tried with the above code and not working. I have used below code to hide/remove error message on the map.
You can make use of the error event of the script tag when loading the Google Maps API.
}