database.js
1.52 KB
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
var mysql = require('mysql');
module.exports = {
init: function (lat, lon) {
var near_show_list = [];
var connection = mysql.createConnection({
"host": "culturegallery.cm2bwcuyukrm.us-east-1.rds.amazonaws.com",
"user": "root",
"password": "dldbwp1207",
"port": "3306",
"database": "showdata"
});
connection.connect();
var dataNum = 0;
connection.query('SELECT COUNT (*) AS cnt FROM SHOW_DATA', function (error, results, field) {
if (error) {
console.log(error);
}
console.log(results[0].cnt);
dataNum = results[0].cnt;
});
connection.query('SELECT id,latitude,longitude FROM SHOW_DATA', function (error, results, field) {
if (error) {
console.log(error);
}
console.log([lat, lon]);
for (var i = 0; i < dataNum; i++) {
var latgap = (lat - results[i].latitude) * 110;
var longap = (lon - results[i].longitude) * 91;
var cal = latgap * latgap + longap * longap;
//내 위치 반경 키로수 ^ 2만큼 cal 값 push -> content 위치
if (cal <= 1600) {
console.log(results[i].id);
near_show_list.push([results[i].id, results[i].latitude, results[i].longitude]);
}
}
});
connection.end();
// return near_show_list;
}
}