-
Notifications
You must be signed in to change notification settings - Fork 0
/
map.js
53 lines (49 loc) · 1.55 KB
/
map.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
const request = require('request');
const querystring = require('querystring');
exports.coord2detailaddr = function (lon, lat, callback) {
let baseUrl = 'https://apis.daum.net/local/geo/coord2detailaddr?';
let opts = {
'x': lon,
'y': lat,
'inputCoordSystem': 'WGS84',
'output': 'json',
'apikey': 'YOUR-APIKEY'
};
let url = baseUrl + querystring.stringify(opts);
request(url, (error, res, body) => {
if (error) {
callback('404 Not Found', null);
} else {
if (JSON.parse(body).new.name) {
callback(null, JSON.parse(body).new.name);
} else {
callback(null, JSON.parse(body).old.name);
}
}
});
};
exports.addr2coord = function (query, callback) {
let baseUrl = 'https://apis.daum.net/local/geo/addr2coord?';
let opts = {
'q': query,
'page_size': 1,
'output': 'json',
'apikey': 'YOUR-APIKEY'
};
let url = baseUrl + querystring.stringify(opts);
request(url, (error, res, body) => {
if (error) {
callback('404 Not Found', null, null, null);
} else {
let data = JSON.parse(body).channel;
if (data.result === '0') {
callback('404 Not Found', null, null, null);
} else {
let title = data.item[0].title;
let lon = data.item[0].lng;
let lat = data.item[0].lat;
callback(null, title, lon, lat);
}
}
});
};