Title: Google map api loading
Last modified: August 21, 2016

---

# Google map api loading

 *  Resolved [landwire](https://wordpress.org/support/users/landwire/)
 * (@landwire)
 * [12 years, 3 months ago](https://wordpress.org/support/topic/google-map-api-loading/)
 * 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://wordpress.org/plugins/leaflet-maps-marker/](https://wordpress.org/plugins/leaflet-maps-marker/)

Viewing 7 replies - 1 through 7 (of 7 total)

 *  Plugin Author [Robert Seyfriedsberger](https://wordpress.org/support/users/harmr/)
 * (@harmr)
 * [12 years, 3 months ago](https://wordpress.org/support/topic/google-map-api-loading/#post-4675797)
 * 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
 *  Thread Starter [landwire](https://wordpress.org/support/users/landwire/)
 * (@landwire)
 * [12 years, 3 months ago](https://wordpress.org/support/topic/google-map-api-loading/#post-4675802)
 * 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](https://wordpress.org/support/users/harmr/)
 * (@harmr)
 * [12 years, 3 months ago](https://wordpress.org/support/topic/google-map-api-loading/#post-4675805)
 * 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](https://wordpress.org/support/users/landwire/)
 * (@landwire)
 * [12 years, 3 months ago](https://wordpress.org/support/topic/google-map-api-loading/#post-4675807)
 * 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](https://wordpress.org/support/users/harmr/)
 * (@harmr)
 * [12 years, 3 months ago](https://wordpress.org/support/topic/google-map-api-loading/#post-4675809)
 * well my id is leafletmapsmarker-googlemaps-loader which should not conflict 😉
 *  Thread Starter [landwire](https://wordpress.org/support/users/landwire/)
 * (@landwire)
 * [12 years, 3 months ago](https://wordpress.org/support/topic/google-map-api-loading/#post-4675810)
 * 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](https://wordpress.org/support/users/harmr/)
 * (@harmr)
 * [12 years, 3 months ago](https://wordpress.org/support/topic/google-map-api-loading/#post-4675813)
 * 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.

 * ![](https://ps.w.org/leaflet-maps-marker/assets/icon.svg?rev=970936)
 * [Leaflet Maps Marker (Google Maps, OpenStreetMap, Bing Maps)](https://wordpress.org/plugins/leaflet-maps-marker/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/leaflet-maps-marker/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/leaflet-maps-marker/)
 * [Active Topics](https://wordpress.org/support/plugin/leaflet-maps-marker/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/leaflet-maps-marker/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/leaflet-maps-marker/reviews/)

## Tags

 * [loading](https://wordpress.org/support/topic-tag/loading/)
 * [script](https://wordpress.org/support/topic-tag/script/)

 * 7 replies
 * 2 participants
 * Last reply from: [Robert Seyfriedsberger](https://wordpress.org/support/users/harmr/)
 * Last activity: [12 years, 3 months ago](https://wordpress.org/support/topic/google-map-api-loading/#post-4675813)
 * Status: resolved