访问时不显示地图

时间:2014-10-06 02:48:10

标签: javascript google-maps google-maps-api-3 web

我有这个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>

1 个答案:

答案 0 :(得分:1)

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');
相关问题