请问下面这段代码单位米如何改为公里


输入城市:
输入起点:
输入目的地:



// 百度地图API功能 var map = new BMap.Map("allmap"); map.centerAndZoom(new BMap.Point(116.404, 39.915), 12); var searchComplete = function (results) { if (transit.getStatus() != BMAP_STATUS_SUCCESS) { return; } var plan = results.getPlan(0); var output = "从" + document.getElementById('txtCity').value + "到" + document.getElementById('txtPoint').value + "驾车需要"; output += plan.getDuration(true) + "<br>"; output += "总路程为:"; output += plan.getDistance(true) + "<br>"; document.getElementById('info').innerHTML = output }; var transit = new BMap.DrivingRoute(map, { renderOptions: { map: map }, onSearchComplete: searchComplete, onPolylinesSet: function () { // setTimeout(function () { alert(output) }, "1000"); } }); function doSearch() { var txtCity = document.getElementById('txtCity'), txtPoint = document.getElementById('txtPoint') if (txtCity.value != '' && txtPoint.value != '') transit.search(txtCity.value, txtPoint.value); }

1个回答

         var searchComplete = function (results) {
            if (transit.getStatus() != BMAP_STATUS_SUCCESS) {
                return;
            }
            var plan = results.getPlan(0);
            var output = "从" + document.getElementById('txtCity').value + "到" + document.getElementById('txtPoint').value + "驾车需要";
            output += plan.getDuration(true) + "<br>";
            output += "总路程为:";
                        ////////////////////////////
            var v = plan.getDistance(true);
            var m = /^(\d+(\.\d+)?)米$/.exec(v);
            if (m) v = (parseFloat(m[1]) / 1000) + '公里';
            output += v + "<br>";
                        ////////////////////////////
            document.getElementById('info').innerHTML = output
        };
Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!
立即提问