Hi Sascha,
Leaflet Maps Marker loads the Google scripts needed for display google maps via the leaflet google plugin with the following script:
<script type='text/javascript' src='http://www.google.com/jsapi?key&ver=3.7'></script>
This script always gets loaded when a maps marker shortcode is used on your site. show_map is just a placeholder and is needed to embedd javascript at the end of each page with a shortcode (and not on every page, just if a shortcode is used). Have a look at leaflet-maps-marker.php function lmm_frontend_enqueue_scripts to see how
scripts are enqueued…
best,
Robert
I have done below to overcome this issue hopefully. At least I do not get any errors anymore!
// to overcome double loading of google scripts have to add this callback and check
$map_SCRIPT_code = "
if (typeof google === 'object' && typeof google.maps === 'object') {
handleApiReady();
} else {
var script = document.createElement('script');
script.type = 'text/javascript';
script.src = 'https://maps.googleapis.com/maps/api/js?v=3.exp&sensor=false&callback=handleApiReady';
document.body.appendChild(script);
}
function handleApiReady() {
my map code.....
mhhh – had a similiar issue before on another site where another plugin also enqueued the Google API (especially as I need different Google API packages which can be loaded as URL parameter).
Not sure if I can prevent double loading, will check if I can at least add a notice in the admin area…
I would guess if an enqueued script has the same name, then wordpress will check if it is enqueued already and then not load it. But some people call their script “google_maps” other “googlemaps” others just “maps_code” I assume. Then also load different google API packages as you say.
At the moment the only solution I could find on the web is the one above.
S
well my id is leafletmapsmarker-googlemaps-loader which should not conflict 😉
I have seen that script name in your code I think, but funny enough it does not show in the enqueued scripts, that I print out to check which scripts are loaded and which ones are not.
What I was saying is because they are all different names (unlike ‘jquery’) it is impossible to check if a google maps script has been loaded with enqueued script I guess.
Anyway, hopefully the above will do the trick 🙂
Actually I dont think that this can be achieved as the scripts are enqueued before any output is generated – so your solution of checking via js if google is available wouldnt work for me I guess.