Example #1
0
        public static List <LocationDto> GetLocations(String str)
        {
            SqlConnection conn = new SqlConnection("Data Source=SQL5016.Smarterasp.net;Initial Catalog=DB_9D6034_Locations;User Id=DB_9D6034_Locations_admin;Password=awedrtgh;");//burdaki kişiler veritabanımın adıdır

            conn.Open();

            String        comm        = str;
            SqlCommand    commandLine = new SqlCommand(comm, conn);
            SqlDataReader dr          = commandLine.ExecuteReader();

            locationDtoList = new List <LocationDto>();


            while (dr.Read())
            {
                locationDto = new LocationDto();

                locationDto.LocationName = dr["LocationName"].ToString();
                locationDto.Lat          = dr["Lat"].ToString();
                locationDto.Lon          = dr["Lon"].ToString();

                locationDtoList.Add(locationDto);
            }

            conn.Close();

            return(locationDtoList);
        }
Example #2
0
        public static String GetLocationNext(List <LocationDto> locationDtoList, BusDto busDto)
        {
            Thread.CurrentThread.CurrentCulture = new CultureInfo("en-US");

            List <LocationDto> nextLocationList = new List <LocationDto>();
            Double             buslat           = Convert.ToDouble(busDto.y);
            Double             buslon           = Convert.ToDouble(busDto.x);
            Double             poilat;
            Double             poilon;
            Double             angleTan;
            Double             angleRangeMin;
            Double             angleRangeMax;
            Double             angleBus = Convert.ToDouble(busDto.angle);
            int a;

            foreach (LocationDto locationDto in locationDtoList)
            {
                poilat = Convert.ToDouble(locationDto.Lat);
                poilon = Convert.ToDouble(locationDto.Lon);

                angleTan = GetAngleTan(poilat, poilon, buslat, buslon);

                angleRangeMin = (angleTan - 90);
                angleRangeMax = (angleTan + 90);

                if (angleBus > angleRangeMin && angleBus < angleRangeMax)
                {
                    a = 1;
                }
                else
                {
                    nextLocationList.Add(locationDto);
                }
            }

            LocationDto nearest  = new LocationDto();
            Double      smallest = int.MaxValue;
            Double      distance;

            foreach (LocationDto locationDto in nextLocationList)
            {
                poilat = Convert.ToDouble(locationDto.Lat);
                poilon = Convert.ToDouble(locationDto.Lon);

                distance = FindMeters(poilat, poilon, buslat, buslon);

                if (distance < smallest)
                {
                    nearest  = locationDto;
                    smallest = distance;
                }
            }

            return(nearest.LocationName);
        }