【问题标题】:Google Maps Marker Content in box框中的谷歌地图标记内容
【发布时间】:2013-12-12 20:17:42
【问题描述】:

我从 MySQL 表中获取坐标、名称和“ID”,但为什么每个标记中的相同文本也是相同的链接?

为什么文字不一样???

它只显示最后一个 ID,但它应该在数据库中的每个元素之后添加另一个标记!

标记位于正确的位置,源代码中的“内容”也正确,但不在标记处,为什么?!

请帮忙

<script type="text/javascript">
    function initialize() {
        var mapOptions = {
            center: new google.maps.LatLng(51.124213, 10.60936),
            zoom: 5,
            mapTypeId: google.maps.MapTypeId.ROADMAP
        };
        var map = new
        google.maps.Map(document.getElementById("map_canvas"),
            mapOptions);
        var contentString;
        var elementeInArray = 0;
        var LatLngList = new Array;

        <? php
        $i = 1;

        foreach($FertigID as $ID) {

            $result = mysql_query("SELECT * FROM Daten_CH WHERE Objektnummer = ".$ID.
                "");

            while ($Ergebnisse = mysql_fetch_array($result)) {
                // Werden alle ergebnisse (ID´s) in einen Array geschriebenn 

                echo $$Ergebnisse["Objektnummer"];

                if (isset($Ergebnisse["Gis_y"]) && $Ergebnisse["Gis_y"] != "" &&
                    $Ergebnisse["Gis_y"] != " ") {

                    echo $i; ?>

                    // MARKER TEXT 

                    contentString = '<?php echo $i; ?> </br><?php echo 
                               $Ergebnisse["Objektname"]; ?> 
                                 </br><a href="Change.php?ID=<?php echo $ID; ?>">
                             <input type="button" value="BEARBEITEN"></button></a>';



                    var Position = new google.maps.LatLng( <? php echo $Ergebnisse["Gis_y"]; ?> , <? php echo $Ergebnisse["Gis_x"]; ?> );

                    var infowindow = new google.maps.InfoWindow({
                        content: contentString
                    });

                    var marker <? php echo $i; ?> = new google.maps.Marker({
                        position: Position,
                        map: map,
                        title: '<?php echo $Ergebnisse["AA_Objektname"]; ?>'
                    });

                    google.maps.event.addListener(marker <? php echo $i; ?> , 'click', function () {

                        infowindow.open(map, marker <? php echo $i; ?> );
                    });

                    LatLngList[elementeInArray] = new google.maps.LatLng( <? php echo $Ergebnisse["Gis_y"]; ?> , <? php echo $Ergebnisse["Gis_x"]; ?> );
                    elementeInArray++;
                    <? php
                }
            }

            $i++;
        }

        ?>

        //  Create a new viewpoint bound
        var bounds = new google.maps.LatLngBounds();
        //  Go through each...
        for (var i = 0, LtLgLen = LatLngList.length; i < LtLgLen; i++) {
            //  And increase the bounds to take this point
            bounds.extend(LatLngList[i]);
        }
        //  Fit these bounds to the map
        map.fitBounds(bounds);

        var opt = {
            minZoom: 1,
            maxZoom: 12
        };
        map.setOptions(opt);
    }

    google.maps.event.addDomListener(window, 'load', initialize);
</script>

【问题讨论】:

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


    【解决方案1】:

    因为您应该将contentString 分配给标记,并使用每个标记分配的内容来更新信息窗口。现在,唯一可用的contentStringlast 创建的。此外,您真的不必创建多个编号标记。您只需要一个标记参考。

    var infowindow = new google.maps.InfoWindow();
    
    var marker = new google.maps.Marker({
        position: Position,
        map: map,
        content: contenString, // <-- assign content to the marker itself
        title: '<?php echo $Ergebnisse["AA_Objektname"]; ?>'
    });
    
    google.maps.event.addListener(marker, 'click', function () {
        infoWindow.setContent(this.content);
        infowindow.open(map, this);
    });
    

    这样就可以了。

    【讨论】:

      猜你喜欢
      • 2011-08-17
      • 1970-01-01
      • 1970-01-01
      • 2020-04-02
      • 1970-01-01
      • 2011-05-17
      • 1970-01-01
      相关资源
      最近更新 更多