-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgeo.js
37 lines (27 loc) · 815 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
26
27
28
29
30
31
32
33
34
35
36
37
"use strict";
const Geocoder = require("../geocode-it/geocoder");
const apiKey = "AIzaSyBiHVp5_5Mq39JzViGie2P5gn2GunXmbHI";
const geocoder = new Geocoder({
apiKey: apiKey
});
module.exports = function doDeo (req, res) {
let address = req.body.address;
let response;
res.setHeader("content-type", "application/json");
if (!address || address === "") {
res.writeHead(400, "Must pass an address");
return res.end()
}
geocoder.geocode(address, onGeo)
function onGeo (err, geos) {
if (err) {
response = JSON.stringify({err: err, stack: err.stack});
res.writeHead(500, "API Error");
return res.end();
}
response = JSON.stringify({
results: geos
})
res.end(response);
}
}