升级WP插件后,Google Maps API V3出现错误

6

在升级WP高级自定义字段后,我遇到了与Google地图有关的问题。地图显示正确,但页面无止境地加载。 FF中的JS错误控制台显示错误:

Error: a is undefined
Source File: https://maps.gstatic.com/intl/en_us/mapfiles/api-3/10/19/main.js
Line: 70

Error: q.queue[Za]() is not a function
Source File: https://maps.gstatic.com/intl/en_us/mapfiles/api-3/10/19/main.js
Line: 74

我生成地图JS的代码如下:

<script type="text/javascript" src="https://maps.google.com/maps/api/js?    key=AIzaSyCwynu3lxKxNPk5DNMWCx8oyGX8ka8_KqU&amp;sensor=false"></script>
<script type="text/javascript">
    //<![CDATA[
    var is_init = false;
    var map;
    function map_init() {
        var latlng = new google.maps.LatLng(<?php echo $lat; ?>, <?php echo $lng; ?    >);
        var myOptions = {
            zoom: <?php echo $zoom; ?>,
            center: latlng,
            scrollwheel: false,
            panControl: false,
            zoomControl: true,
            mapTypeControl: false,
            scaleControl: true,
            streetViewControl: true,
            overviewMapControl: false,
            mapTypeId: google.maps.MapTypeId.<?php echo $maptype; ?>
        };
        map = new google.maps.Map(document.getElementById("map_canvas"), myOp    tions);
        var marker;
        var latlng;

        <?php $i = 0; foreach($markers as $title=>$marker): ?>
        <?php if(!empty($marker['lat']) && !empty($marker['lng']))  { ?>
        latlng = new google.maps.LatLng(<?php echo $marker['lat']; ?>,<?php echo     $marker['lng']; ?>);
        marker<?php echo $i; ?> = new google.maps.Marker({
            position: latlng,
            map: map,
            icon: '/wp-content/themes/iw/marker/<?php echo $marker['typ']; ?    >.png',
            title: '<?php echo $title; ?>'
        });
        google.maps.event.addListener(marker<?php echo $i; ?>, 'click', function()     {   
            window.location.href = '<?php echo $marker['link']; ?>';
        });
            google.maps.event.addListener(marker<?php echo $i; ?>, 'mouseover',     function() {
            jQuery('.sbmlink<?php echo $i; ?>').addClass('mouseover');
        });
        google.maps.event.addListener(marker<?php echo $i; ?>, 'mouseout', func    tion() {
            jQuery('.sbmlink<?php echo $i; ?>').removeClass('mouseover');
        });
        <?php } ?>
        <?php $i++; endforeach; ?>
        is_init = true;

}
    jQuery(function(){
        jQuery('#map_button').click(function(){
            jQuery('#map_canvas').toggle();
            if (!is_init) {
                map_init();
            }
            if(jQuery('#map_button').html() == 'Hier klicken, um die Karte     einzublenden') {
                    jQuery('#map_button').html('Hier klicken, um die Karte auszublenden');
                document.cookie="mapstate=open; path=/;";
            } else {
                    jQuery('#map_button').html('Hier klicken, um die     Karte einzublenden');
                document.cookie="mapstate=closed; path=/;";
            }
        });
        <?php if ($mapstate == 'open' || ($map_default_open &&     !isset($_COOKIE['mapstate']))): ?>
        jQuery('#map_button').click();
        <?php endif; ?>
            jQuery.ajax({
            dataType : 'json',
        //  url : '/wetter.php?ort=<?php echo $custom['wetterort'][0]; ?>',
            success : function(data) {
                jQuery('.wetterzustand').html(data.wetterzustand);
                jQuery('.wettertemperatur').html(data.wettertemperatur + '     &deg;C');
                jQuery('.wettericon').html('<img alt="' +     data.wetterzustand + '" src="' + data.wettericon + '"/>');
            }
        });
    });
    //]]>
    </script>

请仅返回翻译后的文本:请向我们展示生成的JS代码的源代码,不包含任何PHP。 - Dr.Molle
我在FF中没有问题,提供页面链接会更有帮助。 - Dr.Molle
检查自定义字段的值,可能是API没有获取到参数。 - Vikram
1
你可能在加载googlemaps的必要文件和函数方面遇到了问题。防火墙?位置?本地主机?我在去一些没有Google API或超时的地区旅行时经常遇到这个问题。 - Obmerk Kronen
尝试不使用 https:。我遇到过类似的问题,去掉 https 并让它自己选择正确的协议似乎可以解决问题。 - adamj
显示剩余5条评论
1个回答

0

这些错误是因为当我们更新WordPress时,它没有更新jquery-ui,所以我们需要在主题的functions.php中手动插入代码来更新jquery-ui。我之前也遇到了同样的问题,这个方法对我很有帮助。

    function new_google_map_script($post) {

        wp_enqueue_style('admin-main', get_bloginfo('template_url') . '/css/admin-main.css');
        //wp_enqueue_style('jquery-ui', get_bloginfo('template_url') . '/css/jquery-ui.css');
        wp_enqueue_style('wp-jquery-ui');
        wp_enqueue_style('wp-jquery-ui-dialog');
    }
    add_action('wp_enqueue_scripts', 'new_google_map_script');

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接