① 楂樺垎鎮璧 鍥涜屼唬鐮佺殑璇︾粏瑙i噴銆佸囨敞 鍏充簬楂樺痙鍦板浘鐨勫浘鏍囨樉紺
PoiOverlay(Drawablepic, java.util.List<PoiItem>items)
鏍規嵁緇欏畾鐨勫弬鏁版潵鏋勯犱竴涓狿oiOverlay鐨勬柊瀵硅薄銆傞氳繃姝ゆ瀯閫犲嚱鏁板壋寤篜oi鍥懼眰銆
removeFromMap()
灝哖oiOverlay浠庡湴鍥句腑縐婚櫎銆傚幓鎺塒oiOverlay涓婃墍鏈夌殑Marker銆
addToMap(MapViewmv)
灝哖oiOverlay鍔犲叆鍒板湴鍥句腑銆傛坊鍔燤arker鍒板湴鍥句腑銆
zoomToSpan()
縐誨姩闀滃ご鍒板綋鍓嶇殑瑙嗚掋
API實現關鍵字查詢的jsp
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
<title>關鍵字查詢</title>
<link rel="stylesheet" type="text/css" href="/Public/css/demo.Default.css" />
<script language="javascript" src="http://webapi.amap.com/maps?v=1.2&key="></script>
<script language="javascript">
var mapObj;
var marker = new Array();
var windowsArr = new Array();
//基本地圖載入
function mapInit() {
mapObj = new AMap.Map("iCenter");
}
function placeSearch() {
var MSearch;
mapObj.plugin(["AMap.PlaceSearch"], function() {
MSearch = new AMap.PlaceSearch({ //構造地點查詢類
city:"021" //城市
});
AMap.event.addListener(MSearch, "complete", keywordSearch_CallBack);//返回地點查詢結果
MSearch.search("東方明珠"); //關鍵字查詢
});
}
//添加marker&infowindow
function addmarker(i, d) {
var lngX = d.location.getLng();
var latY = d.location.getLat();
var markerOption = {
map:mapObj,
icon:"http://webapi.amap.com/images/" + (i + 1) + ".png",
position:new AMap.LngLat(lngX, latY)
};
var mar = new AMap.Marker(markerOption);
marker.push(new AMap.LngLat(lngX, latY));
var infoWindow = new AMap.InfoWindow({
content:"<h3><font color=\"#00a6ac\"> " + (i + 1) + ". " + d.name + "</font></h3>" + TipContents(d.type, d.address, d.tel),
size:new AMap.Size(300, 0),
autoMove:true,
offset:new AMap.Pixel(0,-30)
});
windowsArr.push(infoWindow);
var aa = function (e) {infoWindow.open(mapObj, mar.getPosition());};
AMap.event.addListener(mar, "click", aa);
}
//回調函數
function keywordSearch_CallBack(data) {
var resultStr = "";
var poiArr = data.poiList.pois;
var resultCount = poiArr.length;
for (var i = 0; i < resultCount; i++) {
resultStr += "<div id='divid" + (i + 1) + "' onmouseover='openMarkerTipById1(" + i + ",this)' onmouseout='onmouseout_MarkerStyle(" + (i + 1) + ",this)' style=\"font-size: 12px;cursor:pointer;padding:0px 0 4px 2px; border-bottom:1px solid #C1FFC1;\"><table><tr><td><img src=\"http://webapi.amap.com/images/" + (i + 1) + ".png\"></td>" + "<td><h3><font color=\"#00a6ac\">名稱: " + poiArr[i].name + "</font></h3>";
resultStr += TipContents(poiArr[i].type, poiArr[i].address, poiArr[i].tel) + "</td></tr></table></div>";
addmarker(i, poiArr[i]);
}
mapObj.setFitView();
document.getElementById("result").innerHTML = resultStr;
}
function TipContents(type, address, tel) { //窗體內容
if (type == "" || type == "undefined" || type == null || type == " undefined" || typeof type == "undefined") {
type = "暫無";
}
if (address == "" || address == "undefined" || address == null || address == " undefined" || typeof address == "undefined") {
address = "暫無";
}
if (tel == "" || tel == "undefined" || tel == null || tel == " undefined" || typeof address == "tel") {
tel = "暫無";
}
var str = " 地址:" + address + "<br /> 電話:" + tel + " <br /> 類型:" + type;
return str;
}
function openMarkerTipById1(pointid, thiss) { //根據id 打開搜索結果點tip
thiss.style.background = '#CAE1FF';
windowsArr[pointid].open(mapObj, marker[pointid]);
}
function onmouseout_MarkerStyle(pointid, thiss) { //滑鼠移開後點樣式恢復
thiss.style.background = "";
}
</script>
</head>
<body onload="mapInit();">
<div id="iCenter"></div>
<div class="demo_box">
<p><input type="button" value="查詢" onclick="placeSearch()"/><br />
</p>
<div id="r_title"><b>關鍵字查詢結果:</b></div>
<div id="result"> </div>
</div>
</body>
</html>
更多0