Javascript 谷歌地图API在加载时卡住,产生错误
我的网站上有很多地图,直到最近我在网站上添加了SSL证书,网站才开始产生错误,地图也停止加载 网站上的一个地图工作得非常完美,这让我相信这与API无关,事实上,这与代码有关Javascript 谷歌地图API在加载时卡住,产生错误,javascript,jquery,google-maps,ssl,Javascript,Jquery,Google Maps,Ssl,我的网站上有很多地图,直到最近我在网站上添加了SSL证书,网站才开始产生错误,地图也停止加载 网站上的一个地图工作得非常完美,这让我相信这与API无关,事实上,这与代码有关 function gd_initialize_ac() { // Create the autocomplete object, restricting the search // to geographical location types. auto
function gd_initialize_ac() {
// Create the autocomplete object, restricting the search
// to geographical location types.
autocomplete = new google.maps.places.Autocomplete(
/** @type {HTMLInputElement} */(document.getElementById('detail_page_map_canvas_fromAddress')),
{types: ['geocode']});
// When the user selects an address from the dropdown,
// populate the address fields in the form.
google.maps.event.addListener(autocomplete, 'place_changed', function () {
gd_fillInAddress_ac();
});
}
function gd_fillInAddress_ac() {
//submit the form
jQuery('#directions').trigger('click');
}
这是谷歌Chrome上的inspect中产生的错误
然后这是与产生的错误相关联的代码。请记住,现在这个网站上有一个https,我不知道这是否有相关性,但是
到目前为止我所做的尝试:
- 将所有http://重命名为https://(无希望)
- 在javascript api中的api末尾添加&libaries。(我在另一个答案上看到了这一点)
function rgmk_find_add_key( $url, $original_url, $_context ) {
$key = get_option( 'rgmk_google_map_api_key' );
// If no key added no point in checking
if ( ! $key ) {
return $url;
}
if ( strstr( $url, "maps.google.com/maps/api/js" ) !== false || strstr( $url, "maps.googleapis.com/maps/api/js" ) !== false ) {// it's a Google maps url
if ( strstr( $url, "key=" ) === false ) {// it needs a key
$url = add_query_arg( 'key',$key,$url);
$url = str_replace( "&", "&", $url ); // or $url = $original_url
}
}
return $url; }
结果证明这与jQuery过时有关
如果其他人有这个问题,请尝试更新jQuery,它应该可以正常工作 你可以发布加载Google API的
脚本标签吗。我怀疑你没有加载Autocomplete
libIt,这是通过Wordpress插件完成的,你想让我发布插件的脚本标签和所有内部信息吗?查看网页的源代码,找到脚本。然后,把它贴在这里。你也可以发布插件php源代码。只是把它添加到问题中。你知道怎么做吗?此后,我尝试在页面底部的页脚中添加直接脚本,但仍然没有成功