1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93
| <!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <meta name="viewport" content="initial-scale=1.0,user-scalable=no" /> <title>百度地图API-批量地址解译</title> <style type="text/css"> body, html { width: 100%; height: 100%; margin: 0; font-family: "微软雅黑"; }
#l-map { height: 400px; width: 100%; }
#r-result { width: 100%; font-size: 14px; line-height: 20px; } </style> <script type="text/javascript" src="http://api.map.baidu.com/api?v=2.0&ak=你的百度开发者申请的 Key!"></script>
</head> <body> <div id="r-result"> <input type="button" value="批量地址解析" onclick="bdGEO()" /> <div id="result"></div> </div>
<script type="text/javascript"> var myGeo = new BMap.Geocoder(); var adds =[ { user: '412412673621', code: '412412673621', address: '北京市昌平区沙河镇沙河高教园', type: 'city' }, { user: '512123213222', code: '551342131242', address: '北京市昌平区史各庄镇', type: 'city' }, { user: '231241241232', code: '511232131232', address: '北京市昌平区史各庄镇', type: 'city' }, ] function bdGEO() { adds.map((add, index) => { geocodeSearch(add, index); })
} function geocodeSearch(add, index) { myGeo.getPoint( add.address, function(point) { if (point) { document.getElementById("result").innerHTML += index + " " + add.code + ":" + add.user + ":" + add.address + ":" + point.lng + "," + point.lat + "</br>"; var address = new BMap.Point(point.lng, point.lat); addMarker(address, new BMap.Label(index + ":" + add.address, { offset : newBMap.Size(20, -10) })); } }, "中国"); }
function addMarker(point, label) { var marker = new BMap.Marker(point); map.addOverlay(marker); marker.setLabel(label); } </script>
</body> </html>
|