0

因此,我使用 PHP/MySQL 将信息加载到一个可以工作的 XML 中,然后我在下面有这段代码,它应该用来制作地图并加载 xml 并在单击时将其插入标记中。这几乎是 100% 复制粘贴自谷歌教程

https://developers.google.com/maps/articles/phpsqlajax_v3#createmap

任何帮助都会很可爱我已经为此苦苦挣扎了好几天

<!DOCTYPE html >
   <head>
    <meta name="viewport" content="initial-scale=1.0, user-scalable=no" />
    <meta http-equiv="content-type" content="text/html; charset=UTF-8"/>
    <title>PHP/MySQL & Google Maps Example</title>
    <script type="text/javascript" src="http://maps.googleapis.com/maps/api/js?key=my           key&sensor=true"></script>
    <script type="text/javascript">
     //<![CDATA[


    function load() {
      var map = new google.maps.Map(document.getElementById("map"), {
       center: new google.maps.LatLng('34.153471', '-118.432123'),
    zoom: 13,
    mapTypeId: 'roadmap'
  });
  var infoWindow = new google.maps.InfoWindow;

  // Change this depending on the name of your PHP file
  downloadUrl("mapXML2.php", function(data) {
        var xml = data.responseXML;
        var markers = xml.documentElement.getElementsByTagName("marker");
        for (var i = 0; i < markers.length; i++) {
            var name = markers[i].getAttribute("name");
            var address = markers[i].getAttribute("address");
            var desc = markers[i].getAttribute("desc");
            var cap = markers[i].getAttribute("eventcap");
            var cur = markers[i].getAttribute("eventcur");
            var type = markers[i].getAttribute("type");
            var point = new google.maps.LatLng(
                parseFloat(markers[i].getAttribute("lat")),
                parseFloat(markers[i].getAttribute("lng")));
            var html = "<b>" + name + "</b> <br/>" + address + "<br/>" + desc + "<br/>" + "Currently " + cur + "/" + cap;
            //var icon = customIcons[type] || {};
            var marker = new google.maps.Marker({
                map: map,
                position: point
            });
            bindInfoWindow(marker, map, infoWindow, html);
        }
    });

function bindInfoWindow(marker, map, infoWindow, html) {
  google.maps.event.addListener(marker, 'click', function() {
    infoWindow.setContent(html);
    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>

  </head>

  <body onload="load()">
    <div id="map" style="width: 500px; height: 300px"></div>
  </body>

</html>
4

1 回答 1

1

您缺少 load() 的右括号

        }
    });
}//**ADD THIS**
function bindInfoWindow(marker, map, infoWindow, html) {
于 2013-01-29T16:48:38.360 回答