百度地图定位问题

发布于:2022-10-09 08:30:59

<style type="text/css">    
.layui-table-cell {    
padding: 0 5px;    
}    
.layui-table-view .layui-table td{    
padding: 0px 0;    
}    
.layui-tab-content{ padding: 1px 0px;}    
#l-map{height:180px;width:100%;}    
#r-result{width:100%;}    
</style>    

<div class="area-title">定位</div>    
<div class="map-area-body">    
<div style="height: 240px; ">    
<input type="text" name="location_name"  id="location_name"  placeholder="" autocomplete="off" class="layui-input ">    
<div id="l-map" class="label-map"></div>    
<div id="searchResultPanel" style="border:1px solid #C0C0C0;width:150px;height:auto; display:none;"></div>    
</div>    
<div class="area-title">详细地址</div>    
<div class="area-localhost-address">    
<input type="text" name="location_detail_address"  id="location_detail_address"  placeholder="" autocomplete="off" class="layui-input ">    
</div>    
<input type="hidden" name="longitude"  id="longitude" value="" >    
<input type="hidden" name="latitude"  id="latitude" value="" >    
</div>    

<script type="text/javascript" src="//api.map.baidu.com/api?v=2.0&ak=A2dZLqPvWUsYSExDbB8QRNvQwNjSwZNc"></script>
<script type="text/javascript" src="/static/admin/js/jquery-1.3.2.js?v=1665275210"></script>    
<script>    
// 百度地图API功能    
function G(id) {    
return document.getElementById(id);    
}    
var cityval="广州";    
var map = new BMap.Map("l-map");    
map.centerAndZoom(cityval,12);                   // 初始化地图,设置城市和地图级别。    
var ac = new BMap.Autocomplete(    //建立一个自动完成的对象    
{"input" : "location_name"    
,"location" : map    
});    
ac.addEventListener("onhighlight", function(e) {  //鼠标放在下拉列表上的事件    
console.log(e.toitem.value);    
var str = "";    
var _value = e.fromitem.value;    
var value = "";    
if (e.fromitem.index > -1) {    
value = _value.province +  _value.city +  _value.district +  _value.street +  _value.business;    
}    
str = "FromItem<br />index = " + e.fromitem.index + "<br />value = " + value;    
value = "";    
if (e.toitem.index > -1) {    
_value = e.toitem.value;    
value = _value.province +  _value.city +  _value.district +  _value.street +  _value.business;    
}    
str += "<br />ToItem<br />index = " + e.toitem.index + "<br />value = " + value;    
G("searchResultPanel").innerHTML = str;    
});    
var myValue;    
ac.addEventListener("onconfirm", function(e) {    //鼠标点击下拉列表后的事件    
var _value = e.item.value;    
myValue = _value.province +  _value.city +  _value.district +  _value.street +  _value.business;    
G("searchResultPanel").innerHTML ="onconfirm<br />index = " + e.item.index + "<br />myValue = " + myValue;    
setPlace();    
});    
map.addEventListener("click", function(e){    
map.clearOverlays();    
var point = new BMap.Point(e.point.lng, e.point.lat);    
var marker =new BMap.Marker(point);    
map.addOverlay(marker);    
var myGeo = new BMap.Geocoder({    
extensions_town: true    
});    
// 根据坐标得到地址描述    
myGeo.getLocation(point, function(result) {    
if (result) {    
console.log(result.address);    
G("location_name").value=result.address;    
}    
});    
});    
function setPlace(){    
map.clearOverlays();    //清除地图上所有覆盖物    
function myFun(){    
var pp = local.getResults().getPoi(0).point;    //获取第一个智能搜索的结果    
map.centerAndZoom(pp, 18);    
map.addOverlay(new BMap.Marker(pp));    //添加标注    
}    
var local = new BMap.LocalSearch(map, { //智能搜索    
onSearchComplete: myFun    
});    
local.search(myValue);    
getBaiduInfo(myValue);    
}    
function getBaiduInfo(myValue){    
layui.use(['layer','jquery'], function () {    
var $ = layui.jquery,    
layer = layui.layer;    
$.ajax({    
url: 'https://api.map.baidu.com/place/v2/search?query='+myValue+'&tag=&region=广州市&output=json&ak=EdTAIG6WAdnghwvpGVSjKUNfLKi4GthD',    
type: 'GET',    
async:false,    
dataType: 'jsonp',    
jsonp:'callback',//传递给请求处理程序或页面的,用以获得jsonp回调函数名的参数名(默认为:callback)    
jsonpCallback:"callback",//自定义的jsonp回调函数名称,默认为jQuery自动生成的随机函数名    
timeout: 5000,    
contentType: 'application/json; charset=utf-8',    
success: function (result) {    
console.log("2"+result);    
if(result.status==0&&result.results){    
console.log(result.results);    
if(result.results.length>0){    
var resls=result.results[0];    
console.log(resls);    
console.log(resls.location.lat);    
$('#latitude').val(resls.location.lat);    
$('#longitude').val(resls.location.lng);    
$('#location_detail_address').val(resls.address);    
}    
}    
},    
});    
});    
}    
//选择来源线索    
layui.use(['form','laydate','tableSelect','asynTreeSelect','dropdown'], function () {    
var tableSelect=layui.tableSelect;    
tableSelect.render({    
elem: '#clue_name',    
searchKey: 'searchKeys',    
checkedKey: 'clue_id',    
searchPlaceholder: '关键词搜索',    
table: {    
url: "/home/Customer/selectclue.html",    
limits: [10, 15, 20, 25, 50, 100,200,500,1000],    
limit: 20,    
cols: [[    
{ type: 'radio' },    
{ field: 'leads_company', title: '公司名称' },    
{    
field: 'create_time', align: 'center', templet: function (d) {    
if (d.convert_time ==0) {    
return d.create_time +"至  未转换";    
}else{    
return d.create_time +'至'+d.convert_time;    
}    
}, title: '线索到转换日期'    
}    
]]    
},    
done: function (elem, data) {    
var select_num=data.data.length;    
var parent_s=[];    
console.log(elem)    
console.log(data)    
layui.each(data.data, function (index, item) {    
$("#clue_name option").each(function () {    
$(this).val(item.leads_id).text(item.leads_company);    
})    
})    
}    
});})    
</script>


阅读 124+

一片空白

父爱如山,不善表达。回想十多年前,总记得父亲有个宽厚的肩膀,小小的自己跨坐在上面,越过人山人海去看更广阔的天空,那个时候期望自己有一双翅膀,能够像鸟儿一样飞得高,看得远。虽然父亲有时会和自己开玩笑,但在做错事的时候会受到严厉的训斥。父亲有双粗糙的大手掌。