我从 mssql 数据库中获取我的纬度和经度,一切正常,但我想通过使用来自同一数据库的信息单击每个标记来添加信息窗口,我不知道该怎么做。
我的 WebForm1.aspx.cs 页面:
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Configuration;
using System.Data.SqlClient;
using System.Data.Sql;
using System.Data.SqlTypes;
using System.Data;
using System.Data.OleDb;
using System.Data.Common;
using System.Windows.Forms;
using AjaxControlTolkit;
namespace WebApplication3
{
public partial class WebForm1 : System.Web.UI.Page
{
SqlConnection sqlConn;
SqlCommand sqlCmd;
SqlDataAdapter sqlDatatAdapter;
DataSet ds_pc;
protected void Page_Load(object sender, EventArgs e)
{
ds_pc = new DataSet();
sqlConn = new SqlConnection(ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString);
sqlCmd = new SqlCommand();
sqlDatatAdapter = new SqlDataAdapter();
sqlCmd = new SqlCommand("dbo.PROCEDURE", sqlConn);
sqlCmd.CommandType = CommandType.StoredProcedure;
sqlDatatAdapter = new SqlDataAdapter(sqlCmd);
sqlDatatAdapter.Fill(ds_pc);
string Locations = "" ;
string txt_site ;
string lat ;
string lon ;
foreach(DataRow dr in (ds_pc.Tables[0]).Rows)
{
if (dr["LATITUDE"].ToString().Trim().Length == 0)
continue;
txt_site = dr["SITE"].ToString();
lat = dr["LATITUDE"].ToString();
lon = dr["LONGITUDE"].ToString();
Locations += Environment.NewLine + " map.addOverlay(new GMarker(new GLatLng(" + lat + "," + lon + ")));";
}
js.Text = @"<script type='text/javascript'>
function initialize() {
if (GBrowserIsCompatible()) {
var map = new GMap2(document.getElementById('map_canvas'));
map.setCenter(new GLatLng(42.00, 43.30), 8);"+Locations+@"map.setUIToDefault();
}
}
</script> ";
}
}
我的 WebForm1.aspx 页面:
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="WebForm1.aspx.cs" Inherits="WebApplication3.WebForm1" %>
<%@ Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="asp" %>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
<title>Google Maps</title>
<script type="text/javascript" src="http://maps.google.com/maps?file=api&v=2&key=MyKeyA&sensor=false"></script>
<body onload="initialize()" onunload="GUnload()">
<div>
<asp:Panel id="Panel1" runat="server">
<asp:Literal id="js" runat="server"></asp:Literal>
<div id="map_canvas" style="width: 1000px; height: 615px"></div>
</asp:Panel>
</div>
</body>
</html>
任何答案/建议都是可观的..谢谢..