动态添加图像到Infowindow

时间:2012-11-11 13:58:13

标签: google-maps-api-3 infowindow

我想知道是否有人可以帮助我。

我正在使用下面的代码将图片加载到HTML页面上,这些页面与当前的“位置”和“用户”ID相关。

<div id="galleria">
                  <?php
                    $dirlist = getFileList($galleryPath, true);
                    $x = 0;
                    foreach($dirlist as $file) { 
                        if((preg_match("/\.jpg$/", $file['name'])) or (preg_match("/\.jpeg$/", $file['name'])) or (preg_match("/\.png$/", $file['name'])) or (preg_match("/\.bmp$/", $file['name'])) or (preg_match("/\.gif$/", $file['name']))) { 
                            echo "<img src='{$file['name']}' />"; 
                            $x = 1;
                        }
                    }
                    if ($x == 0) {
                        echo "<img src='images/noimage.jpg' />";
                    }
                    ?>
                </div>

这很好用,但我在这两个方面遇到了困难。我试图只显示第一张图像并将该图像放在“Infowindow”而不是主页面上。但我必须绝对诚实,并说我甚至不确定从哪里开始。我花了几天时间来达到这一点。

以下代码是脚本中的提取,用于创建标记和Infowindow。

downloadUrl("loadlocationfinds.php?locationid=<?php echo $lid?>", function(data) { 
            var xml = data.responseXML; 
            var markers = xml.documentElement.getElementsByTagName("marker"); 
            var bounds = new google.maps.LatLngBounds(); 
            for (var i = 0; i < markers.length; i++) { 
            var findid = markers[i].getAttribute("findid"); 
            var locationid = markers[i].getAttribute("locationid"); 
            var findosgb36lat = markers[i].getAttribute("findosgb36lat");
            var findosgb36lon = markers[i].getAttribute("findosgb36lon");
            var findcategory = markers[i].getAttribute("findcategory"); 
            var point = new google.maps.LatLng( 
            parseFloat(markers[i].getAttribute("findosgb36lat")), 
            parseFloat(markers[i].getAttribute("findosgb36lon")));
            var html = "<span class='h3 orange'><strong>" + 'Item Found: ' + "</strong></span><br>" + finddescription + "<br>"; 
            var icon = customIcons[findcategory] || {}; 
            var marker = new google.maps.Marker({ 
            map: map, 
            position: point, 
            title: 'Click to view details', 
            icon: icon.icon, 
            shadow: icon.shadow,
            formfindosgb36lat: findosgb36lat,
            formfindosgb36lon: findosgb36lon,
            formfindcategory: findcategory,
            }); 
            bounds.extend(point); 
            map.fitBounds(bounds); 
            bindInfoWindow(marker, map, infoWindow, html);
            google.maps.event.addListener(marker, "click", function() {
            document.getElementById('findosgb36lat').value = this.formfindosgb36lat; 
            document.getElementById('findosgb36lon').value = this.formfindosgb36lon; 
            document.getElementById('findcategory').value = this.formfindcategory; 
            }); 
            } 
            }); 
            } 

            function bindInfoWindow(marker, map, infoWindow, html) {     
            google.maps.event.addListener(marker, 'click', function() {         
            infoWindow.setContent(html);         
            infoWindow.open(map, marker, html);     
            }); 
            } 

我只是想知道是否有人可以看一下这个并提供一些帮助,以便我只能在'Infowindwow'中显示第一张图片。

非常感谢和最诚挚的问候

1 个答案:

答案 0 :(得分:0)

图像被添加到信息窗口的html中

........................
var html = "<span class='h3 orange'><strong>" + 'Item Found: ' + "</strong></span><br>" +     finddescription + "<br>"; 
html+= "<img src=\"image.jpg\" alt=\"My Image\" height=\"Ypx\" width=\"Xpx\"><br>";
........................

X Y 是整数

map