首页 文章

Google Map 在Wordpress中嵌入了Api:服务器拒绝了您的请求

提问于
浏览
0

在这个问题上,我已经半夜了 . 我已经通过iframe将谷歌 Map API嵌入到Wordpress网站中,我收到错误:Google Maps API服务器拒绝了您的请求 . 提供的API密钥无效 .

我的钥匙没问题 . 我把它放在wordpress之外的一个vanilla html文档中,效果很好 .

然后我尝试在header.php中将传感器设置为true . 除了我的控制台出现更多错

无法加载资源:https://www.google.com/maps/embed/v1/place?q=place_idmyplace key = mykey ?wmode = transparent无法加载资源:服务器响应状态为403()**无法发布其余信息,因为我需要更多信誉

我认为问题是将?wmode = transparent附加到密钥的末尾 . 可能会添加什么以及如何删除它?

1 回答

  • 0

    问题出在你的主题上 .

    当您在浏览器检查器(元素选项卡)中查看包含 Map 的页面时,您可以看到该链接以?wmode = transparent
    Elements tab in inspector
    结束

    页面代码不包含?wmode = transparent,您可以在检查器的“源”选项卡上看到它:
    page source sode

    这意味着某些js脚本会修改页面代码 . 在Sources选项卡中浏览脚本,我发现了以下内容:
    js source code

    在第13行,您可以看到问题的根源 . 这是Youtube视频的一些动作,由开发人员完成了一个粗略的错误 . 他们将?wmode = transparent添加到任何iframe的src,包括谷歌 Map .

    我检查了latest version的主题 . 同样的错误 .

    您需要做的是:只需在文件/wp-content/themes/crescent-theme/js/jquery.custom.js中注释第13行,并将其设为:

    ( function( $ ) {
    
        function modifyPosts() {
            /* Fit Vids ---------------------*/
            $('.feature-vid, .postarea').fitVids();
        }
    
    
        //Fix z-index youtube video embedding
        $(document).ready(function (){
            $('iframe').each(function(){
                var url = $(this).attr("src");
                // $(this).attr("src",url+"?wmode=transparent");
            });
        }); 
    
    
        $( document )
        .ready( modifyPosts )
        .on( 'post-load', modifyPosts );
    
    })( jQuery );
    

    如果要更新主题,则必须在同一个js文件中注释类似的行 .

相关问题