gpt4 book ai didi

javascript - 访问时 map 不显示

转载 作者:行者123 更新时间:2023-11-28 00:56:00 25 4
gpt4 key购买 nike

我有这个 HTML 文件(如下),它与此处找到的文件几乎相同。 https://developers.google.com/maps/documentation/javascript/examples/infowindow-simple

我遇到的问题是我认为任何脚本部分或 HTML 都没有任何问题,然后我再次作为志愿者为非营利组织编写此内容,并且我通常不会执行此 HTML 或 javascript 。该文件是由 perl 脚本生成的,所以请对我宽容一些。

请让我知道我做错了什么!

<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="initial-scale=1.0, user-scalable=no">
<meta charset="utf-8">
<title>e-NABLE Event Map</title>
<style>
html, body, #map-canvas {
height: 100%;
margin: 0px;
padding: 0px
}
</style>
<script src="https://maps.googleapis.com/maps/api/js?v=3.exp"></script>
<script>

function initialize() {
var myHome = new google.maps.Latlng(-77.675106,43.090076);
var mapOptions = {
zoom: 4,
center: myHome
};

var map = new google.maps.Map(document.getElementByID('map-canvas'), mapOptions);

var contentString = '<div id="content">'+
'<div id="siteNotice">'+
'</div>'+
'<h1 id="firstHeading" class="firstHeading">Uluru</h1>'+
'<div id="bodyContent">'+
'<p><b>Uluru</b>, also referred to as <b>Ayers Rock</b>, is a large ' +
'sandstone rock formation in the southern part of the '+
'Northern Territory, central Australia. It lies 335&#160;km (208&#160;mi) '+
'south west of the nearest large town, Alice Springs; 450&#160;km '+
'(280&#160;mi) by road. Kata Tjuta and Uluru are the two major '+
'features of the Uluru - Kata Tjuta National Park. Uluru is '+
'sacred to the Pitjantjatjara and Yankunytjatjara, the '+
'Aboriginal people of the area. It has many springs, waterholes, '+
'rock caves and ancient paintings. Uluru is listed as a World '+
'Heritage Site.</p>'+
'<p>Attribution: Uluru, <a href="http://en.wikipedia.org/w/index.php?title=Uluru&oldid=297882194">'+
'http://en.wikipedia.org/w/index.php?title=Uluru</a> '+
'(last visited June 22, 2009).</p>'+
'</div>'+
'</div>';

var myLatlng0 = new google.maps.LatLng(-77.675106,43.090076);

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

var marker0 = new google.maps.Marker({
position: myLatlng0,
map: map,
title: 'e-NABLE Home Base'
});

google.maps.event.addListener(marker0, 'click', function() {
infowindow.open(map,marker0);
});

}

google.maps.event.addDomListener(window, 'load', initialize);

</script>
</head>

<body>
<div id="map-canvas"></div>
</body>

最佳答案

JavaScript 区分大小写。 new google.maps.Latlng(-77.675106,43.090076) 应该是 new google.maps.LatLng(-77.675106,43.090076)document.getElementByID( 'map-canvas') 应为 document.getElementById('map-canvas')。就我个人而言,我不喜欢输入 google.maps 或使用 document.getElementById(),所以我这样做:

var doc = document, bod = document.body, gm = google.maps;
function E(e){
return doc.getElementById(e);
}
var myHome = new gm.LatLng(-77.675106,43.090076);
var canvas = E('map-canvas'); // same as document.getElementById('map-canvas');

关于javascript - 访问时 map 不显示,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26209427/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com