Use vb.net function into javascript through code behind in order to save post back
I have a shared function in vb GetEmployeeLocationJSON()
Public Shared Function GetEmployeeLocationJSON() As String
Dim location As New List(Of Object)()
Using conn As New SqlConnection()
conn.ConnectionString = ConfigurationManager.ConnectionStrings("constr").ConnectionString
Using cmd As New SqlClient.SqlCommand("spGetEmployeeLocation", conn)
cmd.CommandType = CommandType.StoredProcedure
cmd.CommandType = CommandType.Text
'cmd.CommandType = CommandType.StoredProcedure
cmd.Connection = conn
conn.Open()
Using sdr As SqlDataReader = cmd.ExecuteReader()
While sdr.Read()
location.Add(New With { _
.EmployeeId = sdr("EmployeeId"), _
.Latitude = sdr("Latitude"), _
.Longitude = sdr("Longitude") _
})
End While
End Using
End Using
conn.Close()
End Using
This funtion returning co ordinates from database
Now i want to use that code in map
<script type="text/javascript">
var map
function initMap() {
var location = JSON.parse('<%=GetEmployeeLocationJSON %>');
//calling vb function above
console.log(JSON.stringify(location));
var mapOptions = {
center: new google.maps.LatLng(location[0].Latitude, location[0].Longitude),
mapTypeId: 'roadmap'
};
var latlngbounds = new google.maps.LatLngBounds();
map = new google.maps.Map(document.getElementById('map'), mapOptions);
var employeeCoordinates = [];
console.log(location.length);
// $(location).each(function (index, value) {
// console.log('Lat :' + location[index].Latitude + 'Long :' + location[index].Longitude);
// });
for (var i = 0; i < location.length; i++) {
employeeCoordinates.push(new google.maps.LatLng(location[i].Latitude, location[i].Longitude));
console.log('Lat :' + location[i].Latitude + 'Long :' + location[i].Longitude)
var employeePolyline = new google.maps.Polyline({
path: employeeCoordinates,
strokeColor: '#FF0000',
strokeOpacity: 1.0,
strokeWeight: 2
});
for (var i = 0; i < employeeCoordinates.length; i++) {
latlngbounds.extend(employeeCoordinates[i]);
}
map.setCenter(latlngbounds.getCenter(), map.fitBounds(latlngbounds));
employeePolyline.setMap(map);
}
}
function placeMarker(pmLat, pmLong) {
var myLatLng = { lat: 23.29, lng: 38.78 };
myLatLng.lat = parseFloat(pmLat);
myLatLng.lng = parseFloat(pmLong);
console.log(myLatLng)
</script>
<script type="text/javascript" src="https://maps.googleapis.com/maps/api/js?key=AIzaSyBOcMB54vyu6w28bjt59n_JmkdOHrYMjRw&callback=initMap"></script>
Now i want to put the return co ordinates into javascript location variable through page load code behind
I dont know how to make it done
plz help