我的XML没有在infowindow中显示HTML

时间:2017-05-02 15:46:35

标签: javascript xml api web

将MySQL和PHP与Google地图配合使用

XML参考:

<marker id="1" 
title="ABC" 
description="<img src="www.xyz.com/assets/xyz.jpg">
<br/>description about 2nd point. <br/>
<a href="www.xyz.com/index.htm">Read More</a>" 
lat="-33.869843" 
lng="-151.225769" 
type="bar" 
district="xyz" />

Infowindow支持我的HTML,使用图片显示我的标题以及指向我页面的链接:

   downloadUrl('https://storage.googleapis.com/mapsdevsite
               /json/mapmarkers2.xml', function(data) {
        var xml = data.responseXML;
        var markers = xml.documentElement.getElementsByTagName('marker');
        Array.prototype.forEach.call(markers, function(markerElem) {

要编辑的部分

          var id = markerElem.getAttribute('id');
          var name = markerElem.getAttribute('name');
          var details = markerElem.getAttribute('details');
          var type = markerElem.getAttribute('type');
          var point = new google.maps.LatLng(
              parseFloat(markerElem.getAttribute('lat')),
              parseFloat(markerElem.getAttribute('lng')));

类型标记有不同的颜色

          var text = document.createElement('text');
          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);

请帮我完成作业。此致

0 个答案:

没有答案