调用百度API实现通过经度纬度确定位置

供应商表结构:

供应商
 1 CREATE TABLE [dbo].[Supply](
 2     [ID] [int] IDENTITY(1,1) NOT NULL,
 3     [Province] [nvarchar](50) NULL,
 4     [City] [nvarchar](50) NULL,
 5     [Address] [nvarchar](100) NULL,
 6     [Contacter] [nvarchar](50) NULL,
 7     [Lag] [nvarchar](50) NULL,
 8     [Lat] [nvarchar](50) NULL,
 9     [Tel] [nvarchar](50) NULL,
10  CONSTRAINT [PK_Supply] PRIMARY KEY CLUSTERED 
11 (
12     [ID] ASC
13 )WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS  = ON, ALLOW_PAGE_LOCKS  = ON) ON [PRIMARY]
14 ) ON [PRIMARY]
15 
16 GO

代码分三层写的:

Model

Model
 1  public class SupplyModel
 2     {
 3         public SupplyModel()
 4         {
 5         }
 6 
 7         private int _id;
 8         public int ID
 9         {
10             get { return _id; }
11             set { _id = value; }
12         }
13 
14 
15         private string _province;
16         public string Province
17         {
18             get { return _province; }
19             set { _province = value; }
20         }
21 
22         private string _city;
23         public string City
24         {
25             get { return _city; }
26             set { _city = value; }
27         }
28 
29         private string _address;
30         public string Address
31         {
32             get { return _address; }
33             set { _address = value; }
34         }
35 
36         private string _contacter;
37         public string Contacter
38         {
39             get { return _contacter; }
40             set { _contacter = value; }
41         }
42         /// <summary>
43         /// 经度
44         /// </summary>
45         private string _lag;
46         public string Lag
47         {
48             get { return _lag; }
49             set { _lag = value; }
50         }
51         /// <summary>
52         /// 纬度
53         /// </summary>
54         private string _lat;
55         public string Lat
56         {
57             get { return _lat; }
58             set { _lat = value; }
59         }
60 
61         private string _tel;
62         public string Tel
63         {
64             get { return _tel; }
65             set { _tel = value; }
66         }
67     }

DAL

DAL
 1  public class SupplyDAL
 2     {
 3         public SupplyDAL()
 4         {
 5         }
 6 
 7         public bool AddSupply(NeoModel.SupplyModel model)
 8         {
 9             string sql = "INSERT INTO Supply(Province,City,Address,Contacter,Lag,Lat,Tel) VALUES(@Province,@City,@Address,@Contacter,@Lag,@Lat,@Tel)";
10             SqlParameter[] sp = { 
11                                 new SqlParameter("@Province",model.Province),
12                                 new SqlParameter("@City",model.City),
13                                 new SqlParameter("@Address",model.Address),
14                                 new SqlParameter("@Contacter",model.Contacter),
15                                 new SqlParameter("@Lag",model.Lag),
16                                 new SqlParameter("@Lat",model.Lat),
17                                 new SqlParameter("@Tel",model.Tel)
18                                 };
19             return DbHelperSQL.ExecuteSql(sql, sp) > 0;
20 
21         }
22         public DataTable GetSupply()
23         {
24             string strSql = "SELECT * FROM SUPPLY";
25             DataSet ds = DbHelperSQL.Query(strSql);
26             return ds.Tables[0];
27         }
28     }

BLL

BLL
 1   public class SupplyBLL
 2     {
 3         NeoDAL.SupplyDAL dal = new NeoDAL.SupplyDAL();
 4         public SupplyBLL()
 5         {
 6         }
 7 
 8         public bool AddSupply(NeoModel.SupplyModel model)
 9         {
10             return dal.AddSupply(model);
11         }
12         public DataTable GetSupply()
13         {
14             return dal.GetSupply();
15         }
16     }

页面前台:

页面前台
 1 <asp:Content ID="Content1" ContentPlaceHolderID="head" runat="server">
 2     <script src="../Scripts/jquery-1.4.1.min.js" type="text/javascript"></script>
 3     <script language="javascript" src="http://api.map.baidu.com/api?v=1.3"></script>
 4  
 5 </asp:Content>
 6 <asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server">
 7     <input type="hidden" id="lag" runat="server" />
 8     <input type="hidden" id="lat" runat="server" />
 9     <input type="hidden" id="supply" runat="server" />
10     <div id="icaption">
11         <div id="title">
12            baidu地图</div>
13     </div>
14     <div id="itable">
15         <table cellspacing="1" width="1026" align="center">
16             <tr class="tr4">
17                 <td class="td1" width="15%">
18                     一级地区
19                 </td>
20                 <td width="45%">
21                     <asp:Label ID="lbOne" runat="server"></asp:Label>
22                 </td>
23                 <td width="40%" rowspan="5" runat="server" id="tdContainer">
24                 </td>
25             </tr>
26             <tr class="tr4">
27                 <td class="td1" width="15%">
28                     二级地区
29                 </td>
30                 <td width="45%">
31                     <asp:Label ID="lbTwo" runat="server"></asp:Label>
32                 </td>
33             </tr>
34             <tr class="tr4">
35                 <td class="td1" width="15%">
36                     联系人
37                 </td>
38                 <td width="45%">
39                     <asp:Label ID="lbContact" runat="server"></asp:Label>
40                 </td>
41             </tr>
42             <tr class="tr4">
43                 <td class="td1" width="15%">
44                     联系方式
45                 </td>
46                 <td width="45%">
47                     <asp:Label ID="lbTel" runat="server"></asp:Label>
48                 </td>
49             </tr>
50             <tr class="tr4">
51                 <td class="td1" width="15%">
52                     地址
53                 </td>
54                 <td width="45%">
55                     <asp:Label ID="lbAddress" runat="server"></asp:Label>
56                 </td>
57             </tr>
58         </table>
59     </div>
60       <script language="javascript" type="text/javascript">
61           var map = new BMap.Map("MainContent_tdContainer");
62           var point = new BMap.Point(document.getElementById("MainContent_lag").value, document.getElementById("MainContent_lat").value);
63           map.centerAndZoom(point, 17);
64           var opts = { width: 50, height: 20, title: "" };
65           var infoWindow = new BMap.InfoWindow(document.getElementById("MainContent_supply").value, opts);
66           map.openInfoWindow(infoWindow, point);
67           var optss = { type: BMAP_NAVIGATION_CONTROL_ZOOM };
68           map.addControl(new BMap.NavigationControl(optss));
69           map.addControl(new BMap.OverviewMapControl());
70           map.addControl(new BMap.MapTypeControl());
71     </script>
72 </asp:Content>

我这用的是母板页,也可以去掉母版页的标志 

后台

后台
 1  public partial class map : System.Web.UI.Page
 2     {
 3         NeoBLL.SupplyBLL bll = new NeoBLL.SupplyBLL();
 4         protected void Page_Load(object sender, EventArgs e)
 5         {
 6             if (!IsPostBack)
 7             {
 8                 DataTable dt = bll.GetSupply();
 9                 this.lag.Value = dt.Rows[2]["lag"].ToString();
10                 this.lat.Value = dt.Rows[2]["lat"].ToString();
11                 this.supply.Value = dt.Rows[2]["address"].ToString();
12                 this.lbOne.Text = dt.Rows[2]["Province"].ToString();
13                 this.lbTwo.Text = dt.Rows[2]["City"].ToString();
14                 this.lbContact.Text = dt.Rows[2]["Contacter"].ToString();
15                 this.lbTel.Text = dt.Rows[2]["Tel"].ToString();
16                 this.lbAddress.Text = dt.Rows[2]["address"].ToString();
17             }
18         }
19     }
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值