2014-01-10 55 views
0

这里是我的问题,我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> 

回答

0

取而代之的是:

document.getElementById('hfLocationList').value 

做到这一点

document.getElementById('<%= hfLocationList.ClientID %>').value 

希望这有助于。干杯

0

您还可以在asp.net控制的ClientIDMode属性设置为静态

<asp:HiddenField runat="server" ID="hfLocationList" Value="0" ClientIdMode="Static" />