<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf8" />
<meta name="viewport" content="initial-scale=1.0, user-scalable=no" />
<title>批量地址转化</title>
<style type="text/css">
body, html {
width: 100%;
height: 100%;
margin: 0;
font-family: "微软雅黑";
}
#l-map {
height: 300px;
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=n1lV45SnzNE4HUNXuYVFiP9ovayupG3X"></script>
</head>
<body>
<div id="r-result">
<input type="file" name="sfile" id="sfile" size="50">
<br>
<input type="button" value="批量地址解析" onclick="getgps()" />
<div id="result"></div>
<br>
</div>
<p><strong>使用说明:</strong></p>
<ol>
<li><strong style="color:#F00">请采用IE8和以下浏览器</strong>或兼容模式;高版本IE浏览器和谷歌内核的浏览器由于安全问题隐藏本地路径,暂无法使用; </li>
<li>输入文件:txt文件,直接拷贝excel的地址列保存到txt文本文件里,每行一个地址,本脚本已做自动规整,不用特别处理; </li>
<li>输出文件:自动在同路径下生成csv文件; </li>
<li>输出经纬度已进行纠偏,为真实经纬度;</li>
<li>执行效率:每秒约解析2.5个地址,量大建议分多个页面运行。</li>
</ol>
</body>
</html>
<script type="text/javascript">
var index=0;var f;var f2;var myGeo=new BMap.Geocoder();var fso=new ActiveXObject("Scripting.FileSystemObject");function getgps(){tf=getPath(document.getElementById("sfile"));f=fso.OpenTextFile(tf,1,true,false);f2=fso.CreateTextFile(tf.replace(".txt","out.csv"),true);getstart()}function getstart(){var add=f.ReadLine().replace(/[\ |\~|\`|\!|\@|\#|\$|\%|\^|\&|\*|\(|\)|\-|\_|\+|\=|\||\\|\[|\]|\{|\}|\;|\:|\"|\'|\,|\<|\.|\>|\/|\?]/g,"");index++;gpsSearch(add)}function gpsSearch(s){if(!f.AtEndOfStream){setTimeout(window.getstart,400)}else{setTimeout(window.finish,500)}myGeo.getPoint(s,function(point){if(point){f2.WriteLine(index+","+s+","+(point.lng-0.0109732)+","+(point.lat-0.0039575));document.getElementById("result").innerHTML="正在解析:"+index+"."+s+"->>"+point.lng+","+point.lat+""}},"")}function finish(){document.getElementById("result").innerHTML="解析完毕,共"+index+"个地址。";f.close;f2.close}function getPath(obj){if(obj){if(window.navigator.userAgent.indexOf("MSIE")>=1){obj.select();return document.selection.createRange().text}else if(window.navigator.userAgent.indexOf("Firefox")>=1){if(obj.files){return obj.files.item(0).getAsDataURL()}return obj.value}return obj.value}}
</script>