谷歌应用程序地图从工作表中的地址获取地理编码

时间:2018-03-05 13:49:30

标签: google-apps-script

不确定为什么停止工作。我正试图获得纬度和来自地址的经度。在某一点工作。不确定发生了什么。我在U列中列出了地址。

function geocode(){
    var tkhCopy = SpreadsheetApp.openById('xxx').getSheetByName('tkhCopy');
    var range = tkhCopy.getRange('U2:U');
    var addresses = range.getValues();

    // Determine the first row and column to geocode
    var row = range.getRow();
    var column = range.getColumn();

    // Set default destination columns
    var destination = new Array();
    destination[0] = 22; // column + 1;
    destination[1] = 23; // column + 2;

    // tkhCopy.insertColumnsAfter(column, 2);
    var geocoder = Maps.newGeocoder();
    var count = range.getHeight();

    // Iterate through addresses and geocode
    for(i in addresses) {
        var location = geocoder.geocode(
            addresses[i]).results[0].geometry.location);
        tkhCopy.getRange(row, destination[0]).setValue(location.lat);
        tkhCopy.getRange(row++, destination[1]).setValue(location.lng);
        Utilities.sleep(200);
    }
}

1 个答案:

答案 0 :(得分:0)