日期:2014-05-20 浏览次数:20514 次
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %> <head id="Head1" runat="server"> <title>google map</title> <script src="http://maps.google.com/maps?file=api&v=2&key=abcdefg" type="text/javascript"></script> <script type="text/javascript"> //<![CDATA[ function load() { if (GBrowserIsCompatible()) { var map = new GMap2(document.getElementById("map")); //初始化一个地图实例 map.addControl(new GLargeMapControl());//全能控件 map.addControl(new GScaleControl());//比例尺 map.addControl(new GMapTypeControl());//允许用户在地图类型之间切换 map.setCenter(new GLatLng(35.745346,114.291375), 12); //设置地图中心的坐标,中国经纬度及放大倍数 map.enableDoubleClickZoom();//双击可以放大 } var jingdu= new Array(); var weidu= new Array(); var id=new Array(); var num=new Array("01","01","03","04","05","06","07","08","09"); var number=<%=number%>; <% for(int i=0;i<number;i++){ %> jingdu.push(<%=ln[i]%>); weidu.push(<%=la[i]%>); id.push(<%=id[i] %>); <% } %> var myicon = new GIcon();//创建新图标 myicon.iconSize = new GSize(27, 27); myicon.shadowSize = new GSize(45, 37); myicon.iconAnchor = new GPoint(9, 34); myicon.infoWindowAnchor = new GPoint(9, 2); myicon.shadow = "http://google-maps-icons.googlecode.com/files/shadow.png";//指定图标阴影图片 <% for(int k1=0;k1<number;k1++){ %> <% if(k1<=8) { %> myicon.image="http://google-maps-icons.googlecode.com/files/red0"+(<%=k1%>+1)+".png ";//指定图标图片 <% } %> <% else { %> myicon.image="http://google-maps-icons.googlecode.com/files/red"+(<%=k1%>+1)+".png "; <% } %> var gPointCZ; var gMarkCZ; //======================================================================== gPointCZ=new GLatLng(weidu[<%=k1 %>],jingdu[<%=k1%>]); gMarkCZ<%=k1%>=new GMarker(gPointCZ,{icon:myicon,title:"第"+(<%=k1%>+1)+"号点,点击查看更多信息"}); map.addOverlay(gMarkCZ<%=k1%>); //======================================================================== <% } %> } </script> </head> <body style="background-color:#F4FFE4" onload="load()" onunload="GUnload()"> <form id="form1" runat="server"> <div id="map" style="width: 1200px; height: 500px; position: static;"><!--这里放置地图实例,可以设置显示地图的大小--></div> </form> </body> </html>
using System; using System.Data; using System.Configuration; using System.Web; using System.Web.Security; using System.Web.UI; using System.Web.UI.WebControls; using System.Web.UI.WebControls.WebParts; using System.Web.UI.HtmlControls; using System.Collections.Generic; using System.Data.SqlClient; public partial class _Default : System.Web.UI.Page { public IList<double> la=new List<double>(); public IList<double> ln=new List<double>() ; public IList<int> id =new List<int>(); public IList<string> name=new List<string>() ; public int number=0; protected void Page_Load(object sender, EventArgs e) { string mycnnConnectionString1=System.Configuration.ConfigurationSettings.AppSettings[ "ConnectionString"].ToString(); //创建连接字符串 SqlConnection mycnn1 = new SqlConnection(mycnnConnectionString1); mycnn1.Open(); SqlCommand cmd1 = new SqlCommand("select id,lat,lng,name from station ", mycnn1); SqlDataReader dr1 = cmd1.ExecuteReader(); while (dr1.Read()) { //lat la.Add((double)dr1["lat"]); //lng ln.Add((double)dr1["lng"]);///数据库读取float型的数据要用double id.Add((int)dr1["id"]); //name name.Add((string)dr1["name"]); number++; } dr1.Close(); mycnn1.Close(); } }