study.js 1.52 KB
var mysql = require('mysql');

module.exports = {
    nearShow: 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;
    }
}