-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgeo.js
25 lines (24 loc) · 831 Bytes
/
geo.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
require('dotenv').config()
const fs = require('fs')
const endOfLine = require('os').EOL
const { getLocation } = require('./getGoogleLocation')
const outputLatitude = fs.createWriteStream('output-latitude.txt', {})
const outputLongitude = fs.createWriteStream('output-longitude.txt', {})
fs.readFile('input-address.txt', 'utf-8', async (err, file) => {
try {
const lines = file.split('\n')
for (let address of lines) {
const coordinates = await getLocation(address)
console.log({ address, coordinates })
if (coordinates) {
outputLatitude.write(`${coordinates.latitude} ${endOfLine}`)
outputLongitude.write(`${coordinates.longitude} ${endOfLine}`)
} else {
outputLatitude.write(`NULL ${endOfLine}`)
outputLongitude.write(`NULL ${endOfLine}`)
}
}
} catch (error) {
console.log({ err })
}
})