jQuery环境 <script src="http://api.map.baidu.com/api?v=1.5&ak=1b0ace7dde0245f796844a06fb112734"></script> <form action="" id="comForm" name="comForm" method="post" onSubmit="return checkForm();"> <input type="hidden" name="usertype" value="2" /> <fieldset> <legend> 添加分公司/门店 </legend> <table class="deptTable" style="width:90%; margin:0 auto;"> <tr> <td class="label"><label>所属企业<b><sup>*</sup></b></label></td> <td><input type="text" id="comname" name="comname" style="width:260px;" value="<?php echo $comname ?>" disabled></td> </tr> <tr> <td class="label"><label>分公司/门店名<b><sup>*</sup></b></label></td> <td><input type="text" id="shopname" name="comname" style="width:260px;"></td> </tr> <tr> <td class="label"><label>联系人<b><sup>*</sup></b></label></td> <td><input type="text" id="realname" name="realname" style="width:160px;"></td> </tr> <tr> <td class="label"><label>手机号<b><sup>*</sup></b></label></td> <td><input type="text" id="mobile" name="mobile" style="width:160px;"></td> </tr> <tr> <td class="label"><label>联系QQ</label></td> <td><input type="text" id="qq" name="qq" style="width:160px;"></td> </tr> <tr> <td class="label"><label>E-mail</label></td> <td><input type="text" id="email" name="email" style="width:160px;"></td> </tr> <tr> <td class="label"><label>分组</label></td> <td><select name="classid" id = ‘classid‘ style="width:164px;"><option value="0">选择分组</option><?php echo $option_html ;?></select></td> </tr> <tr> <td class="label"><label>企业地址</label></td> <td> <select id="s_province" name="s_province" class ="area"> </select> <select id="s_city" name="s_city" class ="area" > </select> <select id="s_county" name="s_county" class ="area"> </select> <script type="text/javascript">_init_area();</script> <input type="text" name="address" id = ‘address‘ style="width:260px;"><input type = ‘button‘ name ="search" id = ‘locate-btn‘ value ="定位"> <br/>输入地址后,点击“自动定位”按钮可以在地图上定位。<br/> (如果输入地址后无法定位,请在地图上直接点击选择地点) <div class="control-group"> <div id="map" style="width: 600px;height: 300px;"></div> </div>
<!-- 地图显示的地方,请随意 --> </td> </tr> <tr> <td class="label"><label>其它</label></td> <td>开通:<input type="radio" id="issh" name="issh" value="1" checked>是 <input type="radio" id="issh" name="issh" value="0">否</td> </tr> <tr> <td class="label"><label></label></td> <td><input type="button" id = ‘btn‘ value="确定添加" style="width:80px;height:30px;"></td> </tr> </table> <input type="hidden" value="116.403694" name="WVYVMQlQ" id="lbsjd"> <input type="hidden" value="39.916042" name="WVYVMRRQ" id="lbswd"> </fieldset> </form> <!--页面功能说明--> <div style="margin:20px;line-height:200%;color:green;"> <p>页面名称:编辑门店</p> <p>Controllers文件:Csuser.php</p> <p>Views文件夹:user</p> <p>页面文件:addcomshop.php</p> <p>操作权限:企业管理员、门店管理员(关联的健康师)</p> <p>对应数据表:jk_comshop</p> <p>功能点说明:1、分组 从数据表 jk_sysclass 列出该企业门店的分组。2、提交数据后需要更新三个数据表:jk_sysclass 中 infonum(加1);jk_comshop;jk_comuser 中 shopnum 加1</p> </div> <!--结束--> <script> var located = true; //定位坐标 var destPoint = new BMap.Point($(‘#lbsjd‘).val(),$(‘#lbswd‘).val()); //写了俩隐藏域 存放了 初始定位地理位置 $(function(){ /**开始处理百度地图**/ var map = new BMap.Map("map"); map.centerAndZoom(new BMap.Point(destPoint.lng, destPoint.lat), 12);//初始化地图 map.enableScrollWheelZoom(); map.addControl(new BMap.NavigationControl()); var marker = new BMap.Marker(destPoint); map.addOverlay(marker);//添加标注 map.addEventListener("click", function(e){ if(confirm("确认选择这个位置?")){ destPoint = e.point; $(‘#lbsjd‘).val(destPoint.lng); $(‘#lbswd‘).val(destPoint.lat); map.clearOverlays(); var marker1 = new BMap.Marker(destPoint); // 创建标注 map.addOverlay(marker1); } }); var myValue; var local; function setPlace(){ map.clearOverlays(); //清除地图上所有覆盖物 local = new BMap.LocalSearch(map, { //智能搜索 renderOptions:{ map: map} }); located = true; local.setMarkersSetCallback(callback); local.search(myValue); } function addEventListener(marker){ marker.addEventListener("click", function(data){ destPoint = data.target.getPosition(0); }); } function callback(posi){ $("#locate-btn").removeAttr("disabled"); for(var i=0;i<posi.length;i++){ if(i==0){ destPoint = posi[0].point; } posi[i].marker.addEventListener("click", function(data){ destPoint = data.target.getPosition(0); }); } } $("#s_province").change(function(){ $("#locate-btn").attr("disabled","disabled"); local = new BMap.LocalSearch(map, { //智能搜索 renderOptions:{ map: map} }); located = true; local.setMarkersSetCallback(callback); local.search($("#s_province").find(‘option:selected‘).text()); return false; }); $("#s_city").change(function(){ $("#locate-btn").attr("disabled","disabled"); local = new BMap.LocalSearch(map, { //智能搜索 renderOptions:{ map: map} }); located = true; local.setMarkersSetCallback(callback); local.search($("#s_city").find(‘option:selected‘).text()); return false; });
//当下拉框发生变化是 用变化后的值 来重新定位 $("#s_county").change(function(){ $("#locate-btn").attr("disabled","disabled"); local = new BMap.LocalSearch(map, { //智能搜索 renderOptions:{ map: map} }); located = true; local.setMarkersSetCallback(callback); local.search($("#s_county").find(‘option:selected‘).text()); return false; });
//当点击的时候 把address文本框的值取过来查找 $("#locate-btn").click(function(){ if($("#address").val() == ""){ alert("请地址!"); return ; } $("#locate-btn").attr("disabled","disabled"); local = new BMap.LocalSearch(map, { //智能搜索 renderOptions:{ map: map} }); located = true; local.setMarkersSetCallback(callback); local.search($("#address").val());//搜索地理位置 进行定位 return false; }); }) </script>
百度地图API --地理位置定位,布布扣,bubuko.com
原文:http://www.cnblogs.com/bin-pureLife/p/3850832.html