簡體   English   中英

Google Maps Infowindow未顯示

[英]Google Maps Infowindow not showing

我的應用程序中有Google地圖。 除一個問題外,一切都按預期進行。 我的圖釘顯示為氣泡(技術人員姓名),該氣泡正在工作。 但是,如果我單擊該技術人員(圖釘),則應該打開一個信息窗口,其中顯示有關該技術人員的更多信息,例如呼叫數量,與客戶的距離,等...(數據正在傳遞),這是我唯一的問題我面臨的問題是,當我單擊圖釘/技術人員時,信息窗口根本沒有顯示...我已經遍歷了代碼,但似乎找不到我出了錯的地方...

這是我的JavaScript代碼:

    <script type="text/javascript">

    $(document).ready(function () {

        var marker = $("#<%= txtTechnicians.ClientID %>").val();
        var markers = JSON.parse(marker);

        var markerCustomer = $("#<%= txtCustomer.ClientID %>").val();
        var markerCust = JSON.parse(markerCustomer);

        function initialize() {

            var map = new google.maps.Map(document.getElementById("dvMap"), {
                center: new google.maps.LatLng(markerCust[0].lat, markerCust[0].lng),
                zoom: 10,
                mapTypeId: google.maps.MapTypeId.ROADMAP,
                mapTypeControl: true,
                mapTypeControlOptions:
                   {
                       style: google.maps.MapTypeControlStyle.DROPDOWN_MENU,
                       poistion: google.maps.ControlPosition.TOP_RIGHT,
                       mapTypeIds: [google.maps.MapTypeId.ROADMAP,
                         google.maps.MapTypeId.TERRAIN,
                         google.maps.MapTypeId.HYBRID,
                         google.maps.MapTypeId.SATELLITE]
                   },
                streetViewControl: true,
                navigationControl: true,
                navigationControlOptions:
                {
                    style: google.maps.NavigationControlStyle.ZOOM_PAN
                },
                scaleControl: true,
                draggableCursor: 'move'
            });

            var trafficLayer = new google.maps.TrafficLayer();
            trafficLayer.setMap(map);

            var poly = new google.maps.Polyline({ map: map, strokeColor: '#FF8200' });
            poly.setMap(map);

            var lat_lngCust = new Array();
            for (i = 0; i < markerCust.length; i++) {
                var data = markerCust[i]
                var myLatlngCust = new google.maps.LatLng(data.lat, data.lng); lat_lngCust.push(myLatlngCust);
                var markerCustomer = new StyledMarker({
                    styleIcon: new StyledIcon(StyledIconTypes.BUBBLE, { color: "#D20202", text: data.title }),
                    position: myLatlngCust, map: map, title: data.title
                });

                (function (markerCustomer, data) {
                    google.maps.event.addListener(markerCustomer, "click", function (e) {
                        infoWindow.setContent(data.description);
                        infoWindow.open(map, markerCustomer);
                    });
                })(markerCustomer, data);
            }

            var lat_lng = new Array();
            for (i = 0; i < markers.length; i++) {
                var data = markers[i]
                var myLatlng = new google.maps.LatLng(data.lat, data.lng); lat_lng.push(myLatlng);
                var marker = new StyledMarker({
                styleIcon: new StyledIcon(StyledIconTypes.BUBBLE, { color: data.colourcode, text: data.title }),
                    position: myLatlng, map: map, title: data.title
                });

                (function (marker, data) {
                    google.maps.event.addListener(marker, "click", function (e) {
                        infoWindow.setContent(data.description);
                        infoWindow.open(map, marker);
                    });
                })(marker, data);
            }
        }

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

根據您附加的代碼,沒有在任何地方定義infoWindow

我認為您只是錯過了這一行; var infoWindow = new google.maps.InfoWindow();

見下文:

(function (marker, data) {
    google.maps.event.addListener(marker, "click", function (e) {
        infoWindow.setContent(data.description); // @SEE: infoWindow is used but not initialized or declare anywhere within the scope.
        infoWindow.open(map, marker); // same
    });
})(marker, data);

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM