• Resolved landwire

    (@landwire)


    Robert,
    I am using a google map in one of my plugins and therefore am loading the google map script. I have not enqueued it properly yet, but I can do. Of course, this causes a JS error and conflict!

    Was just wondering if I can somehow check if maps markers has loaded the google map script already and then I do not need to load it. I can only see the script ‘show_map’ being enqueued at the front end. How do you load the google maps script? do you use enqueue_script? If so why is it not showing up in all the enqueued script list?

    Does map markers add the google script to every page load in front end?
    Thanks,
    Sascha

    https://www.ads-software.com/plugins/leaflet-maps-marker/

Viewing 7 replies - 1 through 7 (of 7 total)
  • Plugin Author Robert Seyfriedsberger

    (@harmr)

    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='https://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

    Thread Starter landwire

    (@landwire)

    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.....

    Plugin Author Robert Seyfriedsberger

    (@harmr)

    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…

    Thread Starter landwire

    (@landwire)

    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

    Plugin Author Robert Seyfriedsberger

    (@harmr)

    well my id is leafletmapsmarker-googlemaps-loader which should not conflict ??

    Thread Starter landwire

    (@landwire)

    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 ??

    Plugin Author Robert Seyfriedsberger

    (@harmr)

    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.

Viewing 7 replies - 1 through 7 (of 7 total)
  • The topic ‘Google map api loading’ is closed to new replies.