<?php $dizhi=$_POST["dizhi"]; $du= $_POST["du"]; $biao = $_POST["biao"]; $dian = $_POST["dian"]; = new MySQLi("localhost","root","726","ziyuan"); = "insert into ditu values('','{$dizhi}','{$du}','{$biao}','{$dian}')"; =$db->query($sql); if($r) { header("location:baiduditu1.php"); } else { echo "标注失败!"; }
就是普通的添加语句
再来看前台的地图部分
<!DOCTYPE html> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <meta content="initial-scale=1.0, user-scalable=no" /> <style type="text/css"> body, html {width: 100%;height: 100%;margin:0;font-family:"微软雅黑";} #allmap{width:100%;height:500px; border:1px solid #000;} p{margin-left:5px; font-size:14px;} </style> <script type="text/javascript" src="http://api.map.baidu.com/api?v=2.0&ak=你的秘钥"></script> <script src="http://libs.baidu.com/jquery/1.9.0/jquery.js"></script> <title>给多个点添加信息窗口</title> </head> <body background="img/4ef34db0af8b9c924670415e46ae6326.jpg"> <h2>地图显示</h2> <div></div> </body> </html> <script type="text/javascript"> // 百度地图API功能 map = new BMap.Map("allmap"); map.addControl(new BMap.NavigationControl()); //添加默认缩放平移控件 map.addControl(new BMap.OverviewMapControl()); //添加默认缩略地图控件 map.addControl(new BMap.OverviewMapControl({ isOpen: true, anchor: BMAP_ANCHOR_BOTTOM_RIGHT })); //右下角,打开 map.enableScrollWheelZoom(true); //启用滚轮放大缩小,默认禁用 map.centerAndZoom(new BMap.Point(118.024491,36.812252), 15); var data_info = [ <?php $db = new MySQLi("localhost","root","726","ziyuan"); $sqla = "select jingwei,dizhi,biaoti,tem from ditu "; $result = $db->query($sqla); $attra=$result->fetch_all(); ) { echo" [{$v[0]},'地址:{$v[1]}<br/>标题:{$v[2]}<br/>电话:{$v[3]}'], "; } ?> ]; var opts = { width : 350, // 信息窗口宽度 height: 100, // 信息窗口高度 title : "信息窗口" , // 信息窗口标题 enableMessage: }; for(var i=0;i<data_info.length;i++){ content = data_info[i][2]; map.addOverlay(marker); // 将标注添加到地图中 addClickHandler(content,marker); } function addClickHandler(content,marker){ marker.addEventListener("click",function(e){ openInfo(content,e)} ); } function openInfo(content,e){ var p = e.target; var point = new BMap.Point(p.getPosition().lng, p.getPosition().lat); var infoWindow = new BMap.InfoWindow(content,opts); // 创建信息窗口对象 map.openInfoWindow(infoWindow,point); //开启信息窗口 } </script>
这里的标注是根据有几个位置就创建几个,然后就是它的信息窗口
后台代码部分
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>无标题文档</title> </head> <link href="bootstrap.min.css" type="text/css" /> <script type="text/javascript" src="jquery-1.11.2.min.js"></script> <script src="bootstrap.min.js"></script> <style type="text/css"> *{ margin:0px auto; padding:0px } .a1{ color:#F00 } #q1{ width:100%; text-align:center} #q2{ width:100%; text-align:center; color:#999 } </style> <body> <h1 >地图信息管理</h1> <br /> <table cellpadding="0" cellspacing="0"> <tr> <td>地址</td> <td>经纬度</td> <td>标题</td> <td>电话</td> <td>操作</td> </tr> <?php $db = new MySQLi("localhost","root","726","ziyuan"); $sql = "select * from ditu"; $result = $db->query($sql); $attr=$result->fetch_all(); ) { echo "<tr><td>{$v[1]}</td><td>{$v[2]}</td><td>{$v[3]}</td><td>{$v[4]}</td><td><a href='baiduxg.php?id={$v[0]}'>修改</a> <a href='baidusc.php?id={$v[0]}' onclick=\"return confirm('确定删除么')\">删除</a></td></tr>"; } ?> </table> <br /> <p>注:可修改信息中的标题和电话<br />数据删除后地图的标识也会删除</p> </html>
这里的操作就简单一点了,删改查
修改部分代码