study.js 1.25 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;
            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;    
    }
}