è°ç¨localsearchå½æ°ãè¿ä¸ªæ¹æ³è¢«ç§°ä¹ä¸ºæ¨¡ç³æ¥è¯¢ã
å¨ä»¥ä¸çä¾åéï¼ä¸ºäºæ¹ä¾¿å¿«æ·ï¼æåäºç¬¬ä¸ä¸ªæ¥è¯¢ç»æã
è¿æ ·ï¼å½å°å解æâåå®å¸éç§åºâ失败æ¶ï¼ä¼èªå¨searchè¿ä¸ªå°åï¼å¹¶æç¹å¨å°å¾ä¸ã
å®æ´æºä»£ç ï¼
å¤å¶ä»£ç
<html>
<head>
<title>å°å解æ失败æ¶æç´¢</title>
<meta name="Generator" content="EditPlus">
<meta name="Author" content="">
<meta name="Keywords" content="">
<meta name="Description" content="">
<script type="text/javascript" src="api?v=1.2"></script>
</head>
<body>
<div id="divMap" style="width:400px;height:400px;border:solid 1px gray"></div>
<script type="text/javascript">
var map = new BMap.Map("divMap");
map.centerAndZoom(new BMap.Point(108.532769,22.825487), 12); //è¿éæ¯å®ä¹å°äºåå®å¸
var gc = new BMap.Geocoder();
gc.getPoint("åå®å¸éç§åº", function(pt){
if(pt){
map.addOverlay(new BMap.Marker(pt)); //å¦æå°å解ææåï¼åæ·»å 红è²marker
}else{
var ls = new BMap.LocalSearch("åå®å¸");
ls.search("åå®å¸éç§åº");
ls.setSearchCompleteCallback(function(rs){
if (ls.getStatus() == BMAP_STATUS_SUCCESS){
var poi = rs.getPoi(0); //å第1个æ¥è¯¢ç»æ
if(poi){
var pt2 = poi.point;
map.addOverlay(new BMap.Marker(pt2)); //å¦ææ¥è¯¢å°ï¼åæ·»å 红è²marker
}
}else{
alert("fail");
}
});
}
}, "åå®å¸");
</script>
</body>
</html>
温馨提示:答案为网友推荐,仅供参考