地址解析失败时搜索地址添加Maker

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<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="http://api.map.baidu.com/api?v=1.2"></script>
</head>

<body>
<div id="divMap" style="width:1000px;height:500px;border:solid 1px gray"></div>
<script type="text/javascript">
var map = new BMap.Map("divMap");
map.centerAndZoom(new BMap.Point(108.953653, 34.273431), 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("交大");
}
});
}
}, "西安市");
</script>
</body>
</html>


你可能感兴趣的:(html,function,generator)