百度地图怎么看坐标(百度地图 获取地图点击地址名称以及经纬度)

HTML<style type="text/css"> body, html,#allmap {width: 100%;height: 100%;margin:0;font-family:"微软雅黑";}</style><script type="text/javascript" src="https://api....

HTML<style type="text/css"> body, html,#allmap {width: 100%;height: 100%;margin:0;font-family:"微软雅黑";}</style><script type="text/javascript" src="https://api.map.baidu.com/api?v=2.0&ak=你的ak&s=1"></script><div class="layui-form-item"> <label class="layui-form-label">详细地址</label> <div class="layui-input-block"> <input id="address" name="address" class="layui-input white-border" placeholder="请填写详细地址" value="${rentIn.address!}" /> <input type="text" name="lng" id="lng" value="${rentIn.longitude!}"/> <input type="text" name="lat" id="lat" value="${rentIn.latitude!}"> </div> <div id="sitePersonMap" style='width: 50%; height: 50%; position: absolute; display: none; z-index:2'></div></div>JS function validate() { var address = document.getElementsByName('address')[0].value; if (isNull(address)) { alert('请选择地址'); return false; } return true; } //判断是否是空 function isNull(a) { return (a == '' || typeof(a) == 'undefined' || a == null) ? true : false; } document.getElementById('address').onclick = function () { if (document.getElementById('sitePersonMap').style.display == 'none') { document.getElementById('sitePersonMap').style.display = 'block'; } else { document.getElementById('sitePersonMap').style.display = 'none'; } } var map = new BMap.Map("sitePersonMap"); var geoc = new BMap.Geocoder(); //地址解析对象 var markersArray = []; var geolocation = new BMap.Geolocation(); var point = new BMap.Point(116.331398, 39.897445); map.centerAndZoom(point, 12); // 中心点 geolocation.getCurrentPosition(function (r) { if (this.getStatus() == BMAP_STATUS_SUCCESS) { var mk = new BMap.Marker(r.point); map.addOverlay(mk); map.panTo(r.point); map.enableScrollWheelZoom(true); } else { alert('failed' + this.getStatus()); } }, {enableHighAccuracy: true}) map.addEventListener("click", showInfo); //清除标识 function clearOverlays() { if (markersArray) { for (i in markersArray) { map.removeOverlay(markersArray[i]) } } } //地图上标注 function addMarker(point) { var marker = new BMap.Marker(point); markersArray.push(marker); clearOverlays(); map.addOverlay(marker); } //点击地图时间处理 function showInfo(e) { document.getElementById('lng').value = e.point.lng; document.getElementById('lat').value = e.point.lat; geoc.getLocation(e.point, function (rs) { var addComp = rs.addressComponents; var address = addComp.province + addComp.city + addComp.district + addComp.street + addComp.streetNumber; if (confirm("确定要地址是" + address + "?")) { document.getElementById('sitePersonMap').style.display = 'none'; document.getElementById('address').value = address; } }); addMarker(e.point); }

  • 发表于 2022-11-26 15:11:33
  • 阅读 ( 77 )
  • 分类:科技

0 条评论

请先 登录 后评论
浏览:64
浏览:64

585 篇文章

你可能感兴趣的文章

相关问题