当链接点击事件时,谷歌地图InfoWindow不会在地图上打开窗口

时间:2015-05-19 05:48:05

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

信息窗口未在地图视图调试中打开而没有任何错误。

但是我的代码信息窗口没有打开,我没有弄错。

这是我的代码

 columns.Bound(e => e.AssetNumber).Template(@<text></text>).ClientTemplate("<a style=\"cursor: pointer;\" onclick=\"showmapbyassetid('#:AssetId#','#:AssetNumber#');\">#=AssetNumber#</a>").Title("Asset Number");

当我点击链接showmapbyassetid方法调用一切正常我调试但Infowindow没有打开地图视图

这是我的javascript方法

  function showmapbyassetid(_assetid, _assetnumber) {

            var IsAuthorized = '@AssetTrackingSystem.Utils.Authorize.IsAuthorized((System.Data.DataTable)Session["Priviliges"], new Guid(Session["CurrentCompanyId"].ToString()), 3, 2)';
            if (IsAuthorized.toLowerCase() == 'false') {
                alert("You are not authorized to view Asset Details");
                return false;
            }
            //debugger;
            assetid = _assetid;
            if (markerarray != null) {
                //debugger;
                var cnt = null;
                var lat = null, long = null;
                var mycenter = null;
                var got = false;
                $.each(markerarray, function (i, item) {
                    // //debugger;
                    if (item.title.toLowerCase() == _assetnumber.toLowerCase()) {
                        mycenter = new google.maps.LatLng(item.position.B, item.position.k);

                        $.each(infowindowcontent, function (j, info) {
                            //debugger;
                            var iiii = allinfowindows;
                            if (info.indexOf("AssetId=" + _assetid) != -1) {
                                cnt = info;
                                got = true;
                            }
                            if (got)
                                return false;
                        });
                        //debugger;
                        SetDeffColor();
                        closeAllInfoWindows();
                        item.setIcon('http://maps.google.com/mapfiles/ms/icons/yellow-dot.png')
                        var infowindow = new google.maps.InfoWindow({
                            content: cnt
                        });
                        allinfowindows.push(infowindow);
                        map.setCenter(mycenter);
                        infowindow.open(map, item);
                    }
                    if (got)
                        return false;
                });
            }
        }

1 个答案:

答案 0 :(得分:0)

我相信您的代码中缺少某些内容,我的示例是以角度完成的,但显示了创建标记,信息窗口和监听器的过程:

var infoWindow = new google.maps.InfoWindow();

var createMarker = function (info){

    var marker = new google.maps.Marker({
        map: $scope.map,
        position: new google.maps.LatLng(info.latitude, info.longitude),
        title: info.city
    });

    google.maps.event.addListener(marker, 'click', function(){
        var contentString  = '<table class="popup">'+
            '<tbody>'+
            // infowindow content
            '</tbody>'+
          '</table>';
        infoWindow.setContent(contentString);
        infoWindow.open($scope.map, marker);
    });

    $scope.markers.push(marker);
}  

for (i = 0; i < hotels.length; i++){
    createMarker(hotels[i]);
}

$scope.openInfoWindow = function(e, selectedMarker){
    e.preventDefault();
    google.maps.event.trigger(selectedMarker, 'click');
}

希望这对你有所帮助。

您可以查看工作代码here