地址解析:
var map = new BMap.Map("l-map"); map.centerAndZoom(new BMap.Point(117.269945,31.86713), 13); map.enableScrollWheelZoom(true); var index = 0; var myGeo = new BMap.Geocoder(); var adds = [ "地址一","地址二","地址三", ]; function bdGEO(){ var add = adds[index]; geocodeSearch(add); index++; } function geocodeSearch(add){ if(index < adds.length){ setTimeout(window.bdGEO,400); } myGeo.getPoint(add, function(point){ if (point) { document.getElementById("result").innerHTML += index + "b" + add + ":" + point.lng + "," + point.lat + ""; var address = new BMap.Point(point.lng, point.lat); addMarker(address,new BMap.Label(index+":"+add,{offset:new BMap.Size(20,-10)})); } }, "ϟ۾ː"); } // Ҡдؔ֨ӥگ˽,ԴݨҪע function addMarker(point,label){ var marker = new BMap.Marker(point); map.addOverlay(marker); marker.setLabel(label); }
逆地址解析:
// 百度地图API功能 var map = new BMap.Map("l-map"); map.centerAndZoom(new BMap.Point(121.355779,31.185159), 13); map.enableScrollWheelZoom(true); var index = 0; var myGeo = new BMap.Geocoder(); var adds = [new BMap.Point(121.491875,31.25753),]; function bdGEO(){ var pt = adds[index]; geocodeSearch(pt); index++; } function geocodeSearch(pt){ if(index < adds.length-1){ setTimeout(window.bdGEO,400); } myGeo.getLocation(pt, function(rs){ var addComp = rs.addressComponents; document.getElementById("result").innerHTML +=index+":"+adds[index-1].lng + "," + adds[index-1].lat + ":" +addComp.district +""; }); }
使用时请自行接入百度api<script type="text/javascript" src="http://api.map.baidu.com/api?v=3.7&ak=????"></script>