天地图API接口地址批量转换为经纬度的解决方案

<table>
    <tr>
        <td>地址td>
        <td>经纬度td>
    tr>
    <tbody id="content">tbody>
table>

封装接口函数

    function transAddress(address) {
     
        var keyWord = {
     "keyWord": address};
        var url = 'http://api.tianditu.gov.cn/geocoder?ds={"keyWord":"' + address + '"}&tk=1fceeaf80900c98780034dda6e38dcf3';
        $.getJSON(url, function (res) {
     
            var trHtml = "";
            trHtml += "" + res.location.keyWord + "" + res.location.lon + "," + res.location.lat + ""
            $("#content").append(trHtml)
        })
    }

循环导出数据

 //循环导出;
    for (var i = 0; i < add.length; i++) {
     
        console.log();
        transAddress(add[i]);
    }

lockdatav done!

你可能感兴趣的:(地图开发)