0

そのため、PHP/MySQL を使用して情報を XML にロードすると、マップを作成して xml をロードし、クリック時にマーカーにプラグインするコードが下に表示されます。これは、Google チュートリアルからほぼ 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 に答える