为什么PHP中只有一个变量显示在我的标记(Google maps api)上?

时间:2017-07-12 11:55:47

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

所以我的网络服务器上有一个Google-maps API。我可以使用地理位置lat和lng显示标记。当您单击标记时,您可以看到有关它的一些信息。我提供信息" Vorname,Nachname,PLZ,Adresse"但它唯一的表现" Vorname" ?

如何在标记中显示所有变量?

<body>
<div id="map"></div>
<script>
    function initMap() 
    {
    var map = new google.maps.Map(document.getElementById('map'), 
        {
            center: new google.maps.LatLng(51.5167, 9.9167),
            zoom: 6
        });
        var infoWindow = new google.maps.InfoWindow;
        downloadUrl('geomap.php', function(data) 
        {
              var xml = data.responseXML;
              var markers = xml.documentElement.getElementsByTagName('marker');
              Array.prototype.forEach.call(markers, function(markerElem) 
              {
                  var Nachname = markerElem.getAttribute('Nachname');
                  var Vorname = markerElem.getAttribute('Vorname');
                  var Adresse = markerElem.getAttribute('Adresse');
                  var plz = markerElem.getAttribute('plz');
                  var point = new google.maps.LatLng(
                  parseFloat(markerElem.getAttribute('geolat')),
                  parseFloat(markerElem.getAttribute('geolong')));

                  var infowincontent = document.createElement('div');
                  var strong = document.createElement('strong');
                  strong.textContent = Nachname;
                //strong.textContent = Vorname;
                  infowincontent.appendChild(strong);
                  infowincontent.appendChild(document.createElement('br'));

                  var text = document.createElement('text');

                  infowincontent.appendChild(text);
                  var marker = new google.maps.Marker(
                  {
                        map: map,
                        position: point
                  });
                  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=apikey&callback=initMap">
</script>
</body>

1 个答案:

答案 0 :(得分:0)

因为根据您的代码,这是您添加到节点的文字内容中的唯一内容:strong.textContent = Nachname;

如果您想要显示其他变量,则应该类似于strong.textContent = Nachname + ', ' + Vorname + ', ' + plz + ', ' + Adresse;