Ссылка на маркер окна информации - PullRequest
0 голосов
/ 26 июня 2018

У меня есть карта Google, я хотел бы добавить ссылку на информацию о окнах маркеров.Маркеры генерируются из базы данных 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);
              });
            });
          });
        }

Фотография результата:

Демонстрация

Я хотел бы, чтобы текст в сильном, который отображаетимя для ссылки на URL-адрес "bottle.php? id =" равнозначная переменная "id", который уже импортирован

Надеюсь, я хорошо выразился, заранее спасибо

1 Ответ

0 голосов
/ 27 июня 2018

В итоге я нашел решение, вот ссылки:

          var a = document.createElement('a');
          a.textContent = "Visit this store"
          a.href = "/bottle.php?id=" + id;
          infowincontent.appendChild(a);
...