0

我是谷歌地图的新手。。

我成功地从数据库中加载了谷歌地图中的多个标记和信息窗口..

当我加载标记两次时,我在加载信息窗口时遇到问题,第一个信息窗口也显示,所以我在一个标记中有 2 个信息窗口....

我的代码是:

function moveMarker() {          
        document.getElementById("koordinatnya").innerHTML = "Move Marker";

        get('moveMarker', function(data) { //loop marker difference lat,long
            var obj = JSON.parse(data);
            var items = Object.keys(obj);
            var output='';
            markers[item] = markers[item] || new google.maps.Marker({ map: map, icon:"http://localhost/pinMarker/usermarker.png" });            
            markers[item].setPosition(new google.maps.LatLng(obj[item].latitude,obj[item].longitude));

            var boxText = document.createElement("div");
            boxText.style.cssText = "border: 1px solid black; margin-top: 8px; background: yellow; padding: 5px;";
            boxText.innerHTML = obj[item].user.toString();

            var cus_info= {
                 content: boxTextInfo
                ,disableAutoPan: false
                ,maxWidth: 0
                ,pixelOffset: new google.maps.Size(-5, 0)
                ,zIndex: null
                ,boxStyle: { 
                  background: "url('tipbox.gif') no-repeat"
                  ,opacity: 0.90
                 }
                ,closeBoxMargin: "2px 2px 2px 2px"
                ,closeBoxURL: "http://www.google.com/intl/en_us/mapfiles/close.gif"
                ,infoBoxClearance: new google.maps.Size(1, 1)
                ,isHidden: false
                ,pane: "floatPane"
                ,enableEventPropagation: false
            };

            var ibInfo = new InfoBox(cus_info);       
        google.maps.event.addListener(markers[item], 'click', function() {
           ibInfo.open(map, markers[item]); //infowindow opened
       });
    });
}

html代码:

<html>
    <head>

    </head>
    <body>

    <script src="socket.io/socket.io.js"></script>
    <script src="http://code.jquery.com/jquery-latest.min.js"></script>

    <link href="http://localhost/cssjsx/cssx.css" rel="stylesheet" type="text/css">
    <script type="text/javascript" src="http://maps.googleapis.com/maps/api/js?sensor=true"></script>
    <script type="text/javascript" src="http://localhost/cssjsx/jsx.js"></script>
    <script type="text/javascript" src="http://localhost/cssjsx/infobox.js"></script>

    <div class="googlemap">
    <div id="header">header : ltv@gmail.com</div>
    <div id="ltk_mn">menu</div>
        <div id="map_area">
            <div id="map_canvas"></div>
            <div class="text">
                <br />
                <input type="text" id="from" Placeholder="asal"/>
                <input type="text" id="to" Placeholder="tujuan"/>
                <select id="mode">
                    <option value="DRIVING">Driving</option>
                    <option value="WALKING">Walking </option>
                    <option value="BICYCLING">Bicycling</option>
                </select>
                <input type="button" value="Show Route" id="driveit" />
                <br/>
                <div id="testkordinat" onClick="">test koordinat</div>
                <div id="koordinatnya" onClick="">koordinatnya</div>
                <div id="chatBox" onClick="">test chtbox</div>
<a href="http://localhost/get_locations.php">testt link</a>
                <input type="text" id="idglobal" style="display: none;" value="ltv@gmail.com" />
            </div>
        </div>
        <div id="kotak_profile">kotakprofile</div>
        <div id="panelkiri"></div>
        <div id="directions"></div>
    </div>


    </body>
</html>

我希望每个信息窗口只显示一个标记..我是如何实现的?

谢谢..

4

0 回答 0