mustardBees/cmb_field_map

Plugin don´t load his JS and CSS

lonchbox opened this issue · 3 comments

Any idea why the plugin don´t load his own js, this could be the reason the map don´t load in the frontend ?

I figure it out the map metabox only give the latitude and longitude so was necesary to use and script to load the map in the front end, just using the get_post_meta dosen´t work at all.

    $ola_hotel_situation_script = get_post_meta( $post->ID, 'hotel_situation_script_map', true );
        <script type="text/javascript">
        //<![CDATA[
            var map;
            function google_maps_load() {
                var myLatlng = new google.maps.LatLng('<?php echo $hotel_situation_script['latitude']; ?>', '<?php echo $hotel_situation_script['longitude']; ?>');
                var myOptions = {
                    center: myLatlng,
                    zoom: 14,
                    mapTypeId: google.maps.MapTypeId.ROADMAP
                };

                map = new google.maps.Map(document.getElementById("map_canvas"), myOptions);
                //var image = "'.$this->params['icon'].'";
                var myLatLng = new google.maps.LatLng('<?php echo $hotel_situation_script['latitude']; ?>', '<?php echo $hotel_situation_script['longitude']; ?>');
                var beachMarker = new google.maps.Marker({
                    position: myLatLng,
                    map: map,
                //  //icon: ( image != "false" ? image : false )
                });

                try {
                    _google_maps_onload(map,beachMarker,myLatlng);
                } catch(e) {}
            }
            function loadScript() {
                var script = document.createElement("script");
                script.type = "text/javascript";
                script.src = "http://maps.google.com/maps/api/js?sensor=true&callback=google_maps_load";
                document.body.appendChild(script);

                $('.tab_5 a').on('click',function() {
                    //map = $('#map_canvas').gmap().map;
                    google.maps.event.trigger(map, 'resize');
                });
            }
            window.onload = loadScript;
            //google.setOnLoadCallback(google_maps_load);
        //]]>
        </script>
        <div id="map_canvas" style="height: 400px"></div>

This works and also fix this issue too: #1

Could be cool to don´t need to use this script, hope you can include in your code :)

Glad you worked this out and got it sorted!

I will be updating the plugin soon with additional documentation, including example front-end code.

👍