public Form2(OptimalRoute.GeoCoords nowPos, OptimalRoute.GeoCoords needPos, DateTime time) { InitializeComponent(); this.nowPos = nowPos; this.needPos = needPos; this.time = time; }
///////////////////////////////////////////////////////////////////////////////////////////////////////////// public static List <Station> GetStationsAround(OptimalRoute.GeoCoords coords, int radius) { //Math.Atan2(Math.Sqrt(Math.Pow(Math.Cos(b.xCoord * Math.PI / 180) * Math.Sin((b.yCoord - a.yCoord) * Math.PI / 180), 2) + Math.Pow(Math.Cos(a.xCoord * Math.PI / 180) * Math.Sin(b.xCoord * Math.PI / 180) - Math.Sin(a.xCoord * Math.PI / 180) * Math.Cos(b.xCoord * Math.PI / 180) * Math.Cos((b.yCoord - a.yCoord) * Math.PI / 180), 2)), Math.Sin(a.xCoord * Math.PI / 180) * Math.Sin(b.xCoord * Math.PI / 180) + Math.Cos(a.xCoord * Math.PI / 180) * Math.Cos(b.xCoord * Math.PI / 180) * Math.Cos((b.yCoord - a.yCoord) * Math.PI / 180)) * 6372795 double pi180 = Math.PI / 180; double xp = coords.xCoord * pi180; string sss = "(ATAN2(SQRT(POW(" + (Math.Cos(xp)).ToString().Replace(',', '.') + " * SIN((" + (coords.yCoord).ToString().Replace(',', '.') + " - 0.0001 * y_coord) * " + pi180.ToString().Replace(',', '.') + "), 2) + POW(COS(x_coord * " + (0.0001 * pi180).ToString().Replace(',', '.') + ") * " + (Math.Sin(xp)).ToString().Replace(',', '.') + " - SIN(x_coord * " + (0.0001 * pi180).ToString().Replace(',', '.') + ") * " + (Math.Cos(xp)).ToString().Replace(',', '.') + " * COS((" + (coords.yCoord).ToString().Replace(',', '.') + " - 0.0001 * y_coord) * " + pi180.ToString().Replace(',', '.') + "), 2)), COS(x_coord * " + (0.0001 * pi180).ToString().Replace(',', '.') + ") * " + (Math.Sin(xp)).ToString().Replace(',', '.') + " + COS(x_coord * " + (0.0001 * pi180).ToString().Replace(',', '.') + ") * " + (Math.Cos(xp)).ToString().Replace(',', '.') + " * COS((" + (coords.yCoord).ToString().Replace(',', '.') + " - 0.0001 * y_coord) * " + pi180.ToString().Replace(',', '.') + ")) * 6372795) < " + (radius * 1.2).ToString(); //sss = "(ATAN2(SQRT(POW(COS("+coords.xCoord.ToString().Replace(',', '.') + " * PI() / 180) * SIN(("+coords.yCoord.ToString().Replace(',', '.') + " - y_coord) * PI() / 180), 2) + POW(COS(x_coord * PI() / 180) * SIN("+coords.xCoord.ToString().Replace(',', '.') + " * PI() / 180) - SIN(x_coord * PI() / 180) * COS("+coords.xCoord.ToString().Replace(',', '.') + " * PI() / 180) * COS(("+coords.yCoord.ToString().Replace(',', '.') + " - y_coord) * PI() / 180), 2)), SIN(x_coord * PI() / 180) * SIN("+coords.xCoord.ToString().Replace(',', '.') + " * PI() / 180) + COS(x_coord * PI() / 180) * COS("+coords.xCoord.ToString().Replace(',', '.') + " * PI() / 180) * COS(("+coords.yCoord.ToString().Replace(',', '.') + " - y_coord) * PI() / 180)) * 6372795) < " + radius.ToString(); //MessageBox.Show(sss); string read_books = "SELECT * FROM `stations`";// WHERE "+sss; /*MySqlCommand sqlCom = new MySqlCommand(read_books, conn); * sqlCom.ExecuteNonQuery(); * MySqlDataAdapter dataAdapter = new MySqlDataAdapter(sqlCom); * DataTable dt = new DataTable(); * dataAdapter.Fill(dt); * var myData = dt.Select(); * * List<Station> tmp = new List<Station>(); * for (int i = 0; i < myData.Length; i++) * { * tmp.Add(new Station((string)myData[i].ItemArray[0], (string)myData[i].ItemArray[1], (string)myData[i].ItemArray[2], (string)myData[i].ItemArray[3], (int)myData[i].ItemArray[4], (int)myData[i].ItemArray[5], (string)myData[i].ItemArray[6])); * }*/ List <Station> tmp = GetAllStations(); List <Station> result = new List <Station>(); foreach (Station s in tmp) { if (OptimalRoute.GeoCoords.Distance(new OptimalRoute.GeoCoords(s.xCoord, s.yCoord), coords) < radius) { result.Add(s); } } return(result); return(tmp); }