2015-05-19 26 views
0

信息窗口無法在地圖上打開視圖調試沒有任何錯誤。Google地圖InfoWindow在鏈接點擊事件時沒有在地圖上打開窗口

但我沒有得到什麼錯誤,我的代碼信息窗口沒有打開。

這裏是我的代碼

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

當我呼籲所有的鏈接showmapbyassetid方法單擊當調試工作正常,但信息窗口沒有打開查看地圖

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

回答

0

我相信你的代碼中缺少一些東西,我的例子是以角度完成的,但是顯示了創建標記,infowindow和listener的過程:

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

相關問題