2011-12-29 64 views
0

更新 先生,这是我的网络page.I的当前代码根据乌拉圭回合的宝贵意见,但标题是不可见或不显示什么由我Assignig服务器端循环变量客户端阵列

<script runat=server> 

     Dim mgps As New Text.StringBuilder 

     Public ReadOnly Property GPS() As String 
      Get 
       Return mgps.ToString 

      End Get 
     End Property 
     Dim station As New Text.StringBuilder 
     Public ReadOnly Property STA() As String 
      Get 
       Return station.ToString 

      End Get 
     End Property 

    </script> 

    <% Dim con As New OleDbConnection 
     con = New OleDbConnection("Data Source=sml; User ID=sml; Password=sml; provider=OraOLEDB.Oracle") 
     con.Open() 
     Dim cmd As OleDbCommand = New OleDbCommand("Select STA_NAME, GPS_ONE from GPS", con) 

     Dim ds As New DataSet 
     Dim I As Long 

     Dim da As New OleDbDataAdapter(cmd) 
     da.Fill(ds, "GPS") 
     mgps.AppendLine("[") 
     For I = 0 To ds.Tables("GPS").Rows.Count - 1 
      ' mgps.AppendLine("new google.maps.LatLng(" & ds.Tables("GPS").Rows(I).Item("GPS_ONE") & "),") 
      mgps.AppendLine("{GPS:new google.maps.LatLng(" & ds.Tables("GPS").Rows(I).Item("GPS_ONE") & "), Sta_Name:'" & STA & "'},") 
     Next I 
     mgps.AppendLine("];") 

     con.Close() 
     %> 
错过所做的更改

UPDATE2 和JS代码是在这里

for(i=0; i<GPS.length; i++) 
{ 

     var image = 'ico/no.png'; 
     var infowindow = new google.maps.InfoWindow(); 
     var ContentString = GPS[i].TITLE 
     markers[i] = new google.maps.Marker(
     { 
     position: GPS[i].GPS, 
     map: map, 
     draggable:true, 
     icon:image, 
     title:GPS[i].TITLE 

     });      
     google.maps.event.addListener(markers[i], 'click', function() { 
     infowindow.setContent(ContentString); 
     infowindow.open(map,markers[i]); 
     }); 


}  

爵士我的信息窗口不开放什么可能的问题

+0

GPS_ONE中的数据在您的GPS表中看起来像什么? – 2011-12-29 13:24:10

+0

它看起来像这样30.302631872323,73.084871561209 – 2011-12-29 13:25:23

+0

然后根据我的回答下面,它看起来像你缺少新的google.maps.LatLng(部分 – 2011-12-29 13:33:42

回答

0

这取决于你如何存储在您的GPS表中您GPS_ONE列数据,但如果你的for循环是这样的:

for(i=0; i<GPS.length-1; i++) 
{ 

     var image = 'ico/no.png'; 
     markers[i] = new google.maps.Marker(
     { 
     position: GPS[i], 
     map: map, 
     draggable:true, 
     icon:image, 
     title: (i+1) + GPS //why is this here? do you have two variables with the same name or did you mean GPS[i]? 
     });        
} 

,并在您GPS_ONE列中的数据是这样的:

new google.maps.LatLng(31.204549793299,72.264183974237) 

然后你写的应该是工作。

编辑:它看起来像你不是按照上面的示例创建一个谷歌地图latlng对象的数组。试着改变你的循环在你的VB,看起来像这样:

For I = 0 To ds.Tables("GPS").Rows.Count - 1 
     mgps.AppendLine("new google.maps.LatLng(" & ds.Tables("GPS").Rows(I).Item("GPS_ONE") & "),") 
    Next I 

编辑的第二个问题: 您可以将所有内容存储在一个JSON对象,所以

For I = 0 To ds.Tables("GPS").Rows.Count - 1 
     mgps.AppendLine("{GPS:new google.maps.LatLng(" & ds.Tables("GPS").Rows(I).Item("GPS_ONE") & "), Title:'" & titleColumnSourceHere & "'},") 
    Next I 

然后你就可以使用这个JSON对象像这样的:

for(i=0; i<GPS.length-1; i++) 
{ 

     var image = 'ico/no.png'; 
     markers[i] = new google.maps.Marker(
     { 
     position: GPS[i].GPS, 
     map: map, 
     draggable:true, 
     icon:image, 
     title: GPS[i].Title 
     });        
} 

很显然,我会建议重新命名您的GPS可变的东西更适合,因为它现在拥有非GPS数据

+0

我会编辑我的答案,所以它更有意义 – 2011-12-29 13:37:11

+0

您可以创建一个对象包含所有数据,但为了简单起见,只需制作第二个包含标题信息的数组,它们的大小应该相同,因为它们来自相同的数据源,因此只需在title [i]处添加标题(假设您命名你的变量标题,并做所有其他你上次做的东西) – 2011-12-29 14:02:31

+0

当然,我只是将它添加到我的回答 – 2011-12-29 14:10:46