Javascript 访问时不显示地图
我有一个HTML文件(如下),它与这里找到的几乎相同 我的问题是,我没有看到任何脚本部分或HTML有任何错误,然后我再次以志愿者的身份为非营利组织写这篇文章,我通常不做HTML或javascript。这个文件是由一个perl脚本生成的,所以请不要客气 请让我知道我做错了什么Javascript 访问时不显示地图,javascript,google-maps,google-maps-api-3,web,Javascript,Google Maps,Google Maps Api 3,Web,我有一个HTML文件(如下),它与这里找到的几乎相同 我的问题是,我没有看到任何脚本部分或HTML有任何错误,然后我再次以志愿者的身份为非营利组织写这篇文章,我通常不做HTML或javascript。这个文件是由一个perl脚本生成的,所以请不要客气 请让我知道我做错了什么 <!DOCTYPE html> <html> <head> <meta name="viewport" content="initial-scale=1.0, user-sc
<!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 km (208 mi) '+
'south west of the nearest large town, Alice Springs; 450 km '+
'(280 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>
e-NABLE事件映射
html,正文,#地图画布{
身高:100%;
边际:0px;
填充:0px
}
函数初始化(){
var myHome=new google.maps.Latlng(-77.675106,43.090076);
变量映射选项={
缩放:4,
中心:我家
};
var map=new google.maps.map(document.getElementByID('map-canvas'),mapOptions);
var contentString=''+
''+
''+
“乌鲁鲁”+
''+
“Uluru,也称为艾尔斯岩,是一个大型的”+
“南部的砂岩岩层”+
“澳大利亚中部的北领地。它位于335公里(208英里)处”+
“最近的大城镇艾丽斯·斯普林斯西南部;450 ;公里”+
"(280)英里(约160英里)的公路,卡塔特朱塔和乌鲁鲁是两个主要城市"+
“乌卢鲁-卡塔朱塔国家公园的特征。乌卢鲁是”+
“对Pitjantjatjara和Yankunytjatjara来说是神圣的”+
“该地区的土著居民。这里有许多泉水和水坑,”+
“岩洞和古画。乌鲁鲁被列为世界”+
“遗产地。”+
“归属:乌卢鲁,”+
(上次访问日期为2009年6月22日)。'+
''+
'';
var mylatng0=新的google.maps.LatLng(-77.675106,43.090076);
var infowindow0=新建google.maps.InfoWindow({
内容:contentString
});
var marker0=新的google.maps.Marker({
位置:myLatlng0,
地图:地图,
标题:“e-NABLE Home Base”
});
google.maps.event.addListener(marker0,'click',function(){
打开(地图,标记0);
});
}
google.maps.event.addDomListener(窗口“加载”,初始化);
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');
我建议您尝试@PHPGlue的代码,并将答案标记为已接受。它对我很有效。捕捉得很好,但是它对我仍然不起作用。我正在查看html文件,我没有看到语法错误,但仍然没有映射:(NVM,让它工作,但我的信息窗口没有显示。关闭以修复该问题!