Google地图有时无法加载 [英] Google Maps Doesn't Load Sometimes

查看:111
本文介绍了Google地图有时无法加载的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在我的网站上使用Maps API创建了嵌入式地图。它将在大学装载9/10次,但永远不会在家装载。有没有办法解决这个问题,以便它总是加载。



这是它正在使用的脚本:

 < script> 
函数initMap(){
var pointer = {lat:53.827369,lng:-1.594245};
var map = new google.maps.Map(document.getElementById('map'),{
zoom:14,
center:pointer
});

var marker = new google.maps.Marker({
position:pointer,
map:map,
title:'Leeds Beckett University'Headingley Campus''
});

var contentString ='< div id =content>'+
'< div id =siteNotice>'+
'< \ / div>'+
'< h1 id =firstHeadingclass =firstHeading> Leeds Beckett University< \ / h1>'+
'< div id =bodyContent> ;'+
'< p class =maptext>利兹贝克特大学是西约克郡利兹的一所公立大学,在市中心和海丁利有校园。该大学的起源可以追溯到1824年,以利兹机械学院的基础为基础:+ + b $ b'< p class =maptext>< b>邮政编码:< \\ / b个LS1 3HE< \ / p>'+
'< \ / div>'+
'< \ / div>';

var infowindow = new google.maps.InfoWindow({
content:contentString
});


marker.addListener('click',function(){
infowindow.open(map,marker);
});

}

< / script>

mapdiv已包含在我的HTML中。


<解决方案似乎你的问题是因为你没有调用 initMap ,至少是你提供的代码。你可以提供更多关于这个问题的见解吗?

  $(document).ready(function(){
initMap );
});


I have an embedded map created using the Maps API on my website. It will load at university 9/10 times, but will never load at home. Is there a way to fix this so that it will always load.

Here is the script it is using:

                    <script>
                function initMap() {
                var pointer = {lat: 53.827369, lng: -1.594245};
                var map = new google.maps.Map(document.getElementById('map'), {
                zoom: 14,
                center: pointer
                });

                var marker = new google.maps.Marker({
                position: pointer,
                map: map,
                title: 'Leeds Beckett University "Headingley Campus"'
                });

                var contentString = '<div id="content">'+
                '<div id="siteNotice">'+
                '<\/div>'+
                '<h1 id="firstHeading" class="firstHeading">Leeds Beckett University<\/h1>'+
                '<div id="bodyContent">'+
                '<p class="maptext">Leeds Beckett University is a public university in Leeds, West Yorkshire, with campuses in the city centre and Headingley. The university’s origins can be traced to 1824, with the foundation of the Leeds Mechanics Institute<\/p>' +
                '<p class="maptext"><b>Postcode:<\/b> LS1 3HE<\/p>'+
                '<\/div>'+
                '<\/div>';

                var infowindow = new google.maps.InfoWindow({
                content: contentString
                });


                marker.addListener('click', function() {
                infowindow.open(map, marker);
                });

                }

                </script>

The "map" div is already included in my HTML.

解决方案

It seems your issue is because you're not calling initMap, at least from the code you provided. Can you give more insight on the issue?

$(document).ready(function() {
    initMap();
});

这篇关于Google地图有时无法加载的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆