0

I need litte direction with how to do it: I'm saving inside HiddenField values and after that I'm using JSON.parse to:

[Object { LocationID=102, LocationName="9 47 Hall Street", LocationLat="40.69631", more...}, Object { LocationID=13, LocationName="9090 Wilshire Blvd", LocationLat="34.0667", more...}, Object { LocationID=12, LocationName="9150 Wilshire-Palm Building", LocationLat="34.0669", more...}, 129 more...]

the thing is I want to loop over the json and get the values like that

LocationLat = "40.69631"

LocationLng" = -73.96648"

and after that I want so send the value to GoogleMap JS Function

    function getValueFromList() {
        var jsonString = $get('<%= hfLocationList.ClientID %>').value;
        var json = JSON.parse(jsonString);
        for (i in json)  {
            var key = i;
            var val = json[i];

        }
    }

    function initialize() {
        var myLatlng = new google.maps.LatLng(34.052055, -118.460490);//sending the value to here
        var mapOptions = {
            zoom: 20,
            center: myLatlng
        }
        var map = new google.maps.Map(document.getElementById("map-canvas"), mapOptions);

        var marker = new google.maps.Marker({
            position: myLatlng,
        });

        // To add the marker to the map, call setMap();
        marker.setMap(map);
    }

    google.maps.event.addDomListener(window, 'load', initialize);


************************VB Code*****************
 Public Sub GetLocationInfo()
        Dim LocationList As New List(Of LocationInfo)
        Dim dba As New DBAccess
        Dim ds As DataSet = dba.GetUserLocationsByID(m_User.UserID, m_User.UserID, m_User.CompanyCode)
        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
  • 2
    This is not a valid json you have there. – Alex Shilman Jan 14 '14 at 21:16
  • It's hard to tell, but it appears that you have an array. [Loop over your array](http://stackoverflow.com/a/3010848/2970947). – Elliott Frisch Jan 14 '14 at 21:21
  • I add the code behind maybe that will help....I just want to grab the lat,lng from that json and save it to param after that sending it to the GoogleMap function there is any way how to do this? – user3188868 Jan 14 '14 at 21:23

0 Answers0