First step: Define the CS array
CS file in the background program to have an array, this array to define as a public array.
Public string[] lat = null;
Public string[] LNG = NULL;
Step Two: Assign values to the CS array
CS array of values are generally taken from the database, I believe everyone will also, and behind the code will be described, here is not to do a detailed explanation.
Step three: Assign the CS array to the JS array at the front
This step is the key, I choose the method is <%=cs array%>. Such a vague argument is also Baidu, the assignment will be used to the cycle, that is, an element of the assignment of elements.
Background CS Code
Using System;
Using System.Collections.Generic;
Using System.Linq;
Using System.Web;
Using System.Web.UI;
Using System.Web.UI.WebControls;
Using System.Data.OleDb;
Using System.Data;
Using System.Collections;
public partial class VideoSource:System.Web.UI.Page
{
Public string[] lat = null;//Store latitude value
Public string[] LNG = null;//Store Longitude value
public int lng_len = 0;//used to get array lengths
public int k = 0;//for Assignment loops
protected void Page_Load (object sender, EventArgs e)
{
ArrayList lng_list = new ArrayList ();
ArrayList lat_list = new ArrayList ();
OleDbConnection con = new OleDbConnection (@ "Provider=microsoft.ace.oledb.12.0;data source=" + Server.MapPath ("App_ DATA/DATABASE1.ACCDB "));
Con. Open ();
String sql = "SELECT * from Tb_videos";
Try
{
OleDbDataAdapter gh = new OleDbDataAdapter (sql, con);
DataSet ds = new DataSet ();
Gh. Fill (DS);
Con. Close ();
foreach (DataRow DR in DS. Tables[0]. Rows)
{
Lng_list. ADD (Dr[2]. ToString ());
Lat_list. ADD (Dr[3]. ToString ());
}
}
Catch
{
Con. Dispose ();
}
LNG = (string[]) lng_list. ToArray (typeof (String));
Lat = (string[]) lat_list. ToArray (typeof (String));
Lng_len = Lng_list. Count;
}
ASPX code
<script type= "Text/javascript" >
var Jingdu = new Array ();
var Weidu = new Array ();
<%
for (int k=0;k<lng_len;k++) {
%>
Jingdu.push ("<%=lng[k]%>");
Weidu.push ("<%=lat[k]%>");
<%
}
%>
var latlng=[];
for (Var i=0;i<jingdu.length;i++) {
Latlng.push (New Google.maps.LatLng (jingdu[i],weidu[i));
}
</script>
The code I used to solve the problem was tested and passed.