示例#1
0
 private void FindHospital_Tapped(object sender, TappedRoutedEventArgs e)
 {
     listDis.Clear();
     double disHos = 0;
     bool check = true;
     for (int i = 0; i < listAdd.Count; ++i)
     {
         int j = 0;
         double x = 0;
         double y = 0;
         string addText = listAdd[i].XY;
         Regex theReg = new Regex(@"(\S+)");
         MatchCollection theMatches = theReg.Matches(addText);
         foreach (Match item in theMatches)
         {
             if (j == 0)
             {
                 x = Convert.ToDouble(item.ToString().Replace(".", ","));
                 ++j;
             }
             if (j == 1)
             {
                 y = Convert.ToDouble(item.ToString().Replace(".", ","));
             }
         }
         if (check == true)
         {
             disHos = (x - xMe) * (x - xMe) + (y - yMe) * (y - yMe);
             disMin.x = x;
             disMin.y = y;
             disMin.ID = listAdd[i].ID;
             disMin.Name = listAdd[i].Name;
         }
         else
         {
             if ((x - xMe) * (x - xMe) + (y - yMe) * (y - yMe) < disHos)
             {
                 disHos = (x - xMe) * (x - xMe) + (y - yMe) * (y - yMe);
                 disMin.x = x;
                 disMin.y = y;
                 disMin.ID = listAdd[i].ID;
                 disMin.Name = listAdd[i].Name;
             }
         }
         Distance dis = new Distance(x,y,listAdd[i].ID,listAdd[i].Name,disHos);
         listDis.Add(dis);
     }
     ShowDrirectLine();
 }
示例#2
0
 private void NextHospital_Tapped(object sender, TappedRoutedEventArgs e)
 {
     foreach (var item in listDis)
     {
         if (item.ID == disMin.ID && listDis.Count > 1)
         {
             listDis.Remove(item);
             disMin = new Distance();
             break;
         }
     }
     if (listDis.Count != 0)
     {
         disMin = listDis[0];
         foreach (var item in listDis)
         {
             if (disMin.distanceHospital < item.distanceHospital)
             {
                 disMin = item;
             }
         }
         ShowDrirectLine();
     }
     else
     {
         DistanceText.Text = "Lỗi, mời bạn chọn tìm kiếm điểm gần nhất";
     }
 }