my-google-maps-plugin not working

Hello Ladies and Gentlemen,

I have tried to work through your tutorial from here:
https://premium.wpmudev.org/blog/google-maps-shortcode/

I have added the short code in this page of my site:
http://www.iarc.ch/map-test/

Unfortunately it just doesn't work. I wanted to ask you friendly to help me and get this running, because I want to understand and learn how this works. :smirk:

I extra disabled all other plugins and changed to a default theme, but it didn't help at all.

I gave you the support rights to have a look on my site, what should or could be done, to get this working.

Please please help :nerd:

kind regards,
Roger

  • Adam Czajczyk

    Hello Roger,

    I hope you're well today and thank you for your question!

    I admit I never tried Daniel's solution but I assume there may either be some error in the code you are using or API has changes since the time the article was posted. I have visited your site and there's a Google Maps JS error reported in browser console when editing the post with shortcode.

    Know having a full access to your plugin I'm not able to test it so you might want to post a full code of it (the one that you are actually using) as gist or into pastebin and share a link to it here so I could check it.

    I think however that you might want to consider a bit more robust solution that would be our Google Maps plugin. Have you already tried it? You will find it here:

    https://premium.wpmudev.org/project/wordpress-google-maps-plugin/

    Best regards,
    Adam

  • Vaishnava

    Sir Adam,

    thank you so much for your reply. The thing ist I have to develope an own plugin for my purposes, because after evaluating tons of google maps plugins inclusive yours, no one covers our demands. I am fearing, there is a problem with the enqueueing the script although it appears in the source code of the page. Also the link to the google maps api generates a #038 code instead a &, when I view the source. I changed some little things from the original tutorial like the wp_admin_enqueue to wp_enqueue_scripts because it should run in the normal front end.
    here is the code, may you as a professional see what my problem is?

    <?php
    /**
     * Plugin Name: My Google Maps Shortcode
     * Plugin URI: http://danielpataki.com
     * Description: Allows users to add flexible Google Maps to post content
     * Version: 1.0.0
     * Author: Daniel Pataki
     * Author URI: http://danielpataki.com
     * License: GPL2
     */
    
    add_shortcode( 'map1', 'mgms_map' );
    function mgms_map() {
    echo	'<div id="map">TextTester</div>
    	<script>
    		function initMap() {
    			var map = new google.maps.Map(document.getElementById(' . 'map ' . '), {
    			zoom: 11,
    			center: {lat: 41.876, lng: -87.624}
    			});
    		}
    	</script>';
    }
    
    function add_scripts() {
      wp_enqueue_script('google-maps', 'https://maps.googleapis.com/maps/api/js?key=AIzaSyDW5vOxCkU1pwS2PD_gjfp33rpbT1AaN3M&callback=initMap', array(), '1.0', true );
    }
    add_action('wp_enqueue_scripts', 'add_scripts')
    ?>
  • Vaishnava

    I really believe it's a problem with enqueing the function, because it it makes
    wp_enqueue_script('google-maps', 'https://maps.googleapis.com/maps/api/js?key=AIzaSyDW5vOxCkU1pwS2PD_gjfp33rpbT1AaN3M&callback=initMap', array(), '1.0', true );
    to this in the source
    <script type='text/javascript' src='https://maps.googleapis.com/maps/api/js?key=AIzaSyDW5vOxCkU1pwS2PD_gjfp33rpbT1AaN3M&

    #038
    ;callback=initMap&
    #038
    ;ver=1.0'></script>

Thank NAME, for their help.

Let NAME know exactly why they deserved these points.

Gift a custom amount of points.