fso.CreateTextFile无法生成txt文档的问题
如题,我在百度地图API中写了一段脚本,遍历坐标点,获得他们和另外一点的距离。 这个功能是实现了的。http://lbsyun.baidu.com/jsdemo.htm#a1_2
但是,结果想要保存的时候出现了一些问题,fso.CreateTextFile无法生成txt文档。请指教一下
另外,用到的pointArr如何输出到txt文档(前面还没调通,目前能想到的就是本办法,在for循环中s.WriteLine来实现了),这个大神也可以顺手指点一下。
本人js刚摸两三天,解答尽可能详细一点。 十分感谢!
程序代码:
<!DOCTYPE html> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <meta name="viewport" content="initial-scale=1.0, user-scalable=no" /> <style type="text/css"> body, html,#allmap {width: 100%;height: 100%;overflow: hidden;margin:0;font-family:"微软雅黑";} </style> <script type="text/javascript" src="//api.map.baidu.com/api?v=2.0&ak=您的密钥"></script> <title>测距</title> </head> <body> <div id="allmap"></div> </body> </html> <script type="text/javascript"> // 百度地图API功能 var map = new BMap.Map("allmap"); var point = new BMap.Point(116.404, 39.915); map.centerAndZoom(point, 15); var min_dist=1000000000 var pointArr = [ {x:30.312903,y:120.382029,title:"A",dist:""}, {x:30.215855,y:120.024568,title:"B",dist:""}, {x:30.18015,y:120.174968,title:"C",dist:""}, {x:30.324994,y:120.164399,title:"D",dist:""}, {x:30.24884,y:120.305074,title:"E",dist:""} ]; // alert(pointArr.length) for (var i = 0; i < pointArr.length; i++) { var newpoint = new BMap.Point(pointArr[i].y,pointArr[i].x); pointArr[i].dist= map.getDistance(point,newpoint).toFixed(2); //alert("距离是:" + min_dist+' 米。'); } var path = prompt("输入保存路径和文件名","D:\\dist.txt"); var fso = new ActiveXObject("Scripting.FileSystemObject"); var s = fso.CreateTextFile(path, true); alert("创建"); s.WriteLine('This is a line'); //s.WriteLine(pointArr); s.Close(); </script>
[此贴子已经被作者于2019-11-12 16:20编辑过]