链接标记窗口信息

时间:2018-06-25 21:04:46

标签: javascript google-maps google-maps-markers

我有一个谷歌地图,我想在标记的Windows信息上添加一个链接。 这些标记是从mysql数据库生成的。

我试图了解我恢复的代码,但无法在信息窗口中添加链接。

(您无法运行代码)

var infoWindow = new google.maps.InfoWindow;

          // Change this depending on the name of your PHP or XML file
          downloadUrl('xml.php', function(data) {
            var xml = data.responseXML;
            var markers = xml.documentElement.getElementsByTagName('marker');
            Array.prototype.forEach.call(markers, function(markerElem) { //loop
              var id = markerElem.getAttribute('id');                    //stock id variable
              var name = markerElem.getAttribute('name');                //stock name variable
              var address = markerElem.getAttribute('address');           //stock address variable
              var type = markerElem.getAttribute('type');                 //stock type variable
              var point = new google.maps.LatLng(              //Recovered the coordinates for the markers 
                  parseFloat(markerElem.getAttribute('lat')),
                  parseFloat(markerElem.getAttribute('lng')));

              var infowincontent = document.createElement('div');         //Displays name in strong
              var strong = document.createElement('strong');
              strong.textContent = name
              infowincontent.appendChild(strong);

              infowincontent.appendChild(document.createElement('br'));     //Back to the line

              var text = document.createElement('text');            //Displays type
              text.textContent = type
              infowincontent.appendChild(text);

              var text = document.createElement('text');     //Displays id (Irrelevant)
              text.textContent = id
              infowincontent.appendChild(text);

              infowincontent.appendChild(document.createElement('br')); //Back to the line

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

结果照片:

Demonstration

我想使用强文本,该文本应显示为指向已导入的URL“ bottle.php?id =”等于变量“ id”的链接

我希望我表现得很好,在此先感谢您

1 个答案:

答案 0 :(得分:0)

我最终找到了解决方案,以下是链接的解决方案:

AddPrimaryKey
相关问题