From 970c5b7876d634aa22177e28d7fbd5aa66563e0c Mon Sep 17 00:00:00 2001 From: EkoJr Date: Mon, 3 Apr 2017 11:21:07 -0700 Subject: [PATCH] Added JS Google Map Auth Fail Alert #201 The Alert occures when SimpleMap > General Options page is loaded, and when Geocode Address button is pressed. A listener function and a check was added. Unfortunatly, the callback function for GeoCoder wasn't initiating when no API Key was used. --- classes/simplemap.php | 34 +++++++++++++++++++++------------- 1 file changed, 21 insertions(+), 13 deletions(-) diff --git a/classes/simplemap.php b/classes/simplemap.php index de3edb5..cffd6e5 100644 --- a/classes/simplemap.php +++ b/classes/simplemap.php @@ -688,20 +688,28 @@ function general_options_js_script() { do_action( 'sm-general-options-js' ); ?> function codeAddress() { - // if this is modified, modify mirror function in master-js php function - var d_address = document.getElementById("default_address").value; - - geocoder = new google.maps.Geocoder(); - geocoder.geocode( { 'address': d_address }, function( results, status ) { - if ( status == google.maps.GeocoderStatus.OK ) { - var latlng = results[0].geometry.location; - document.getElementById("default_lat").value = latlng.lat(); - document.getElementById("default_lng").value = latlng.lng(); - } else { - alert("Geocode was not successful for the following reason: " + status); - } - }); + var gm_api_key = document.getElementById("api_key").value; + // if this is modified, modify mirror function in master-js php function + var d_address = document.getElementById("default_address").value; + + if ( gm_api_key ) { + geocoder = new google.maps.Geocoder(); + var a = geocoder.geocode( { 'address': d_address }, function( results, status ) { + if ( status == google.maps.GeocoderStatus.OK ) { + var latlng = results[0].geometry.location; + document.getElementById("default_lat").value = latlng.lat(); + document.getElementById("default_lng").value = latlng.lng(); + } else { + alert("Geocode was not successful for the following reason: " + status); + } + }); + } else { + gm_authFailure(); + } } + function gm_authFailure() { + alert("Google Maps API Key is Required within Map Configuration."); + };