-
Notifications
You must be signed in to change notification settings - Fork 0
/
formscript.js
65 lines (49 loc) · 1.65 KB
/
formscript.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
//On github for reference
let latitudes = [['lat']]; //what is this double bracket thing
let longitudes = [['lng']];
function getLatLng() {
let sheet = SpreadsheetApp.getActiveSpreadsheet().getSheetByName("Form Responses 1"); //Find a better way than name maybe
const range = sheet.getDataRange();
const allcells = range.getValues();
const length = allcells.length;
for(let i = 1; i < length; i++)
{
let textLocationColumn = allcells[i][6];
let lat = lng = 0;
if(textLocationColumn)
{
const areaCode = textLocationColumn;
console.log(areaCode);
areaCodeToLatLng(areaCode);
}
else
{
console.log("????");
}
}
sheet.getRange('N1') // write to latitude column
.offset(0, 0, latitudes.length).setValues(latitudes);
sheet.getRange('O1') // write to longitude column
.offset(0, 0, longitudes.length).setValues(longitudes);
}
function areaCodeToLatLng(areaCode)
{
let areaCodeSheet = SpreadsheetApp.getActiveSpreadsheet().getSheetByName("Geocoding");
const range = areaCodeSheet.getDataRange();
const allcells = range.getValues();
let code = areaCode.toString().charCodeAt(0);
code -= 65;
//console.log(areaCode + " " + code);
//Then jump to the correct cell in the second sheet
if(code > 12 || code < 0)
{
console.log("Invalid area code");
return;
}
let lat = allcells[code + 1][1]; //Get the lat and lng from a given row
let lng = allcells[code + 1][2];
console.log(areaCode + " lat: " + lat + "lng: " + lng);
latitudes.push([lat]); //dddoesn't work
longitudes.push([lng]);
//how do javascript objects/return values work
}