百度地图API:如何查询数自己的数据库标注地图并让标注显示在最佳

由于在实际项目中经常需要查询自己的数据库去标注地图,所以特地写了这个例子,,数据库为oracle,把数据库查询出来的数据绑定到前台gridview控件,点击数据中的任何一行,实现标注。效果图:

地图标注代码,

position,name,address,phone,typeid为后台数据库查询出来的字段//地图标注 function maker(position,name,address,phone,typeid) {map.clearOverlays();var cc = position;var x = cc.split(",")var point=new BMap.Point(x[0], x[1])var myIcon =new BMap.Icon("images/fly.gif", new BMap.Size(45, 70), { offset: new BMap.Size(0, -5),imageOffset: new BMap.Size(0, 0) });//创建标注图标var marker = new BMap.Marker(point,{icon:myIcon}); // 创建标注map.addOverlay(marker); // 将标注添加到地图中map.centerAndZoom(point,16); //设定地图的中心点和坐标并将地图显示在地图容器中var opts1 = {title : ‘<span style="font-size:20px;color:#0A8021">客户详细资料</span>’};var infoWindow =new BMap.InfoWindow("<div><b>姓名:</b>"+name+"</br><b>地址:</b>"+address+"</br><b>电话:</b>"+phone+"</br><b>客户类型:</b>"+typeid+"</br></a></div>", opts1);marker.addEventListener("click", function () { this.openInfoWindow(infoWindow); }); }后台主要代码protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e){string position = "";if (e.Row.RowType == DataControlRowType.DataRow){e.Row.Attributes["onmouseover"] = "ItemOver(this)";int count = GridView1.Rows.Count;for (int i = -1; i < count; i++){position = GridView1.DataKeys[e.Row.RowIndex].Value.ToString();}try{//string sql = "select position,name,address,phone from sys_cust where custid=" + position;string sql = "select t.custid,t.position as 坐标,t.name as 姓名,t.address as 地址,t.phone as 电话,t.typeid,s.typeid,s.name as 客户类型 from sys_custtype s,sys_cust t where t.typeid=s.typeid and t.custid=" + position;DataSet ds = sqlHelper.getDataSet(sql);foreach (DataRow dr in ds.Tables[0].Rows){jwd = dr["坐标"].ToString();name = dr["姓名"].ToString();address = dr["地址"].ToString();phone=dr["电话"].ToString();typeid=dr["客户类型"].ToString();}}catch (Exception ee){Response.Write(ee.Message);}e.Row.Attributes.Add("onclick", "maker(‘" + jwd + "’,’" + name + "’,’" + address + "’,’" + phone + "’,’" + typeid+ "’);");}}

代码写的比较水,但是可以实现基本功能,高手见笑。

下载地址:下载

生命不息,奋斗不止,就像我们常说的一句话;

百度地图API:如何查询数自己的数据库标注地图并让标注显示在最佳

相关文章:

你感兴趣的文章:

标签云: