2011-12-28 33 views
0

我使用谷歌地圖api v3並希望使用循環在JS中的標記也顯示來自Db的infowindow上的數據。我想在地圖上製作標記,因爲我將數據添加到數據庫中。 我的工作已經完成,但我無法競爭我的目標。在地圖功能谷歌地圖v3標記使用循環

<% 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") 
     For I = 0 To ds.Tables("GPS").Rows.Count - 1 
      Dim GPS As String = ds.Tables("GPS").Rows(I).Item("GPS_ONE") 
     Next 

     %> 

和JS代碼,使標記

var map = new google.maps.Map(document.getElementById("map_canvas"), myOptions); 

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


var GPS='<%=GPS %>' 

var Infowindow=GPS 

var image = 'ico/Ch.png'; 
var LatLng = new google.maps.LatLng(GPS); 
var marker0 = new google.maps.Marker({ 
    draggable: true, 
    position: LatLng, 
    map: map, 
    icon:image, 
    title:"" 

}); 

google.maps.event.addListener(marker0, 'click', function() { 
infowindow.setContent(Infowindow); 
    infowindow.open(map,marker0); 

}); 

通過這個代碼我是unalbe以使一根marker.I要在地圖上創建標記,因爲我在DB列

添加GPS

回答

0

google.maps.LatLng要求兩個參數。您正在使用一個:GPS。既然你不說什麼GPS看起來像什麼值,這應該讓你開始。

取代:

var GPS='<%=GPS %>' 

有:

var GPS = '<%=GPS %>'.replace(/ /g, '').split(','); 

取代:

var LatLng = new google.maps.LatLng(GPS); 

有:

var LatLng = new google.maps.LatLng(GPS[0], GPS[1]); 
+0

我得到Compilati關於「GPS未聲明」的錯誤,以及如何使所有標記與從服務器端循環JS中的循環? – 2011-12-29 03:52:35