這裏是我的問題,我strated使用谷歌地圖和事情是:從數據庫中獲取緯度,經度並將其設置爲JS功能
在我的網站我有RadComoboBox與我從數據庫中填充的位置,並在右側
asp面板和它我正在顯示谷歌地圖。問題是我希望用戶選擇位置
從RCB中它將顯示在地圖上(所有的想法是拿走lat,lon並將其發送到google的簡單代碼並在地圖)
我的想法是保存所有的位置到ArrayList和序列化,並在JS使用它,desirailed保存到HiddenField後
它。
但沒有什麼真正發生的問題!!!
這裏是我的代碼:
**返回代碼VB.NET* ** * **
Imports System.Web.Script.Serialization.JavaScriptSerializer
Public Class LocationInfo
Private m_LocationID As Integer = 0
Private m_LocationName As String = Nothing
Private m_LocationLat As String = Nothing
Private m_LocationLng As String = Nothing
#Region "LocationInfo Properties"
Public Property LocationID() As Integer
Get
Return m_LocationID
End Get
Set(ByVal value As Integer)
m_LocationID = value
End Set
End Property
Public Property LocationName() As String
Get
Return m_LocationName
End Get
Set(ByVal value As String)
m_LocationName = value
End Set
End Property
Public Property LocationLat() As String
Get
Return m_LocationLat
End Get
Set(ByVal value As String)
m_LocationLat = value
End Set
End Property
Public Property LocationLng() As String
Get
Return m_LocationLng
End Get
Set(ByVal value As String)
m_LocationLng = value
End Set
End Property
#End Region
End Class
Public Sub GetLocationInfo()
Dim LocationList As New List(Of LocationInfo)
Dim dba As New DBAccess
Dim ds As DataSet = dba.GetUserLocationsByID(m_User.UserID)
Dim dt As DataTable = ds.Tables(0)
For Each dr As DataRow In dt.Rows()
Dim locationInfo As New LocationInfo
locationInfo.LocationName = dr("LocationName")
locationInfo.LocationLat = dr("Lat")
locationInfo.LocationLng = dr("lng")
locationInfo.LocationID = dr("LocationID")
LocationList.Add(locationInfo)
Next
Dim oSerilzer As New System.Web.Script.Serialization.JavaScriptSerializer
Dim sJson As String = oSerilzer.Serialize(LocationList)
hfLocationList.Value = sJson.ToString()
End Sub
*****************************aspx code*****************************
function getValueFromList() {
var jsonString = document.getElementById('hfLocationList').value;
var arr_from_json = JSON.parse(jsonString);
}
var map;
function initialize() {
var mapOptions = {
zoom: 8,
center: new google.maps.LatLng(34.052055, -118.460490)
};
map = new google.maps.Map(document.getElementById('map-canvas'),
mapOptions);
}
google.maps.event.addDomListener(window, 'load', initialize);
<td>Locations:</td>
<td>
<asp:HiddenField runat="server" ID="hfLocationList" Value="0"/>
<telerik:RadComboBox ID="rcbLocations" runat="server">
</telerik:RadComboBox>
<div id="map-canvas">
<asp:Panel ID="Panel1" runat="server" Width="150px" Height="150px">
</asp:Panel>