Google地图有时无法加载
我在我的网站上使用Maps API创建了嵌入式地图。它将在大学装载9/10次,但永远不会在家装载。有没有办法解决这个问题,以便它总是会加载。Google地图有时无法加载
下面是它使用的脚本:
<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>
“地图”格已经包含在我的HTML。
看来你的问题是因为你不打电话initMap
,至少从你提供的代码。你能否就这个问题提供更多的见解?
$(document).ready(function() {
initMap();
});
我认为你只需要称为“地图”的div,使其工作,因为脚本通过查找div创建元素?或者我错了? – RachMcrae
不,您还需要调用initMap。我会更新我的答案。 – jdmdevdotnet
确实确实解决了它,所以谢谢你,先生。 – RachMcrae
这是一个嵌入式地图上的网页,我试图在家里访问不是在移动,对不起。 – RachMcrae