【问题标题】:Why is only one variable displaying on my marker (Google maps api) in PHP?为什么在 PHP 中我的标记(Google 地图 api)上只显示一个变量?
【发布时间】:2017-12-16 20:15:12
【问题描述】:

所以我的网络服务器中有一个 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>

【问题讨论】:

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


    【解决方案1】:

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

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

    【讨论】:

    • 我试图实现多个 strong.textContent ,猜我错了。谢谢!!!
    猜你喜欢
    • 2015-05-22
    • 1970-01-01
    • 1970-01-01
    • 2021-02-06
    • 1970-01-01
    • 1970-01-01
    • 2016-11-09
    • 2014-09-29
    • 2021-05-14
    相关资源
    最近更新 更多