body, html {
width: 100%;
height: 100%;
margin: 0;
font-family: "微软雅黑";
font-size: 14px;
}
#l-map {
height: 300px;
width: 100%;
}
#r-result {
width: 100%;
}
关键字输入提示词条function G(id) {
return document.getElementById(id);
}
var map = new BMap.Map("l-map");
map.centerAndZoom("成都", 12);
var ac = new BMap.Autocomplete(
{
"input": "suggestId"
, "location": map
});
ac.addEventListener("onhighlight", function (e) {
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
index = " + e.fromitem.index + "
value = " + value;
value = "";
if (e.toitem.index > -1) {
_value = e.toitem.value;
value = _value.province + _value.city + _value.district + _value.street + _value.business;
}
str += "
ToItem
index = " + e.toitem.index + "
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
index = " + e.item.index + "
myValue = " + myValue;
setPlace();
});
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);
}
一键复制
编辑
Web IDE
原始数据
按行查看
历史