Google 地图信息窗口在 link 单击事件时未在地图上打开 window

Google maps InfoWindow not opening window on map when link click event

信息 window 没有打开地图视图调试没有任何错误。

但是我没有发现我的代码信息有什么问题 window 没有打开。

这是我的代码

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

当我在调用时单击 link showmapbyassetid 方法,调试时一切正常,但信息window 未在地图视图中打开

这是我的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;
                });
            }
        }

我认为您的代码中缺少某些内容,我的示例是在 angular 中完成的,但显示了创建标记、信息窗口和侦听器的过程:

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