Google MAP未加载自定义标记

时间:2017-01-19 16:57:12

标签: javascript php mysql google-maps google-maps-api-3

我已经阅读了有关Google MAP API的其他问题,据我所知,它们似乎都没有解决我的问题。我跟着"过时的"有关使用MySQL查询和自定义标记在我的网站上安装Google地图的说明。在更正了示例代码生成的所有错误之后,我终于正确生成了xml文件,(http://www.l3valuation.com/portal/maptest2.php)。

然而,在加载实际的地图页面时,我得到的只是一个没有地图的白页。也没有生成错误。如果之前已经回答了这个问题并且我错过了,我会道歉。我的眼睛变得朦胧,我可能会错过它。

我的地图页面代码如下

   <head>
    <meta name="viewport" content="initial-scale=1.0, user-scalable=no" />
    <meta http-equiv="content-type" content="text/html; charset=UTF-8"/>
    <title>L3 CARDS</title>
    <style>
      /* Always set the map height explicitly to define the size of the div
       * element that contains the map. */
   #map {
    height: 100%;
    width: 100%;
    }
    /* Optional: Makes the sample page fill the window. */
    html, body {
    height: 100%;
    width: 100%;
    margin: 0;
    padding: 0;
   }
   </style>
   </head>
    <body>
    <div id="map"></div>
    <script>
      var customLabel = {
      1: {
label: 'A'
  },
  2: {
label: 'I'
  },
        3: {
label: 'L'
  },
  4: {
    label: 'R'
 }
  5: {
    label: 'G'
  }
};

function initMap() {
    var map = new google.maps.Map(document.getElementById('map'), {
      center: new google.maps.LatLng(45.3791021, -122.7613788),
      zoom: 15
    });
var infoWindow = new google.maps.InfoWindow;

      // Change this depending on the name of your PHP or XML file
      downloadUrl('maptest2.php', function(data) {
var xml = data.responseXML;
var markers = xml.documentElement.getElementsByTagName('marker');
Array.prototype.forEach.call(markers, function(markerElem) {
var id = markerElem.getAttribute('id');
var ReportType = markerElem.getAttribute('ReportType');
var Address = markerElem.getAttribute('Address');
var point = new google.maps.LatLng(
    parseFloat(markerElem.getAttribute('Lat')),
    parseFloat(markerElem.getAttribute('lng')));
var infowincontent = document.createElement('div');
var strong = document.createElement('strong');
strong.textContent = Address
infowincontent.appendChild(strong);
infowincontent.appendChild(document.createElement('br'));

var text = document.createElement('text');
text.textContent = Address
infowincontent.appendChild(text);
var icon = customLabel[ReportType] || {};
var marker = new google.maps.Marker({
  map: map,
  position: point,
  label: icon.label
});
          marker.addListener('click', function() {
            infoWindow.setContent(infowincontent);
            infoWindow.open(map, marker);
          });
        });
      });
    }



  function downloadUrl(url, callback) {
    var request = window.ActiveXObject ?
        new ActiveXObject('Microsoft.XMLHTTP') :
        new XMLHttpRequest;

    request.onreadystatechange = function() {
      if (request.readyState == 4) {
        request.onreadystatechange = doNothing;
        callback(request, request.status);
      }
    };

    request.open('GET', url, true);
    request.send(null);
  }

  function doNothing() {}
</script>
<script async defer
src="https://maps.googleapis.com/maps/api/js?key=ValidAPIKey is installed&callback=initMap">
</script>
</body>
</html>

1 个答案:

答案 0 :(得分:-1)

我在自定义标签中缺少逗号。