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); }
public static List <BusDto> Find() { Thread.CurrentThread.CurrentCulture = new CultureInfo("en-US"); int index = 0; String value = GetData(); List <BusDto> list = new List <BusDto>(); while (true) { busDto = new BusDto(); index = value.IndexOf("<SBB:nhat_no>", index); busDto.name = CutUntilChar(value.Substring(index + 13, 10), '<'); index++; if (busDto.name.Contains("n=")) { break; } index = value.IndexOf("ts", index); busDto.x = CutUntilChar(value.Substring(index + 7, 25), ','); busDto.y = BeginCutCommaToEnd(value.Substring(index + 7, 25)); index++; index = value.IndexOf("<SBB:naci>", index); String temp = CutUntilChar(value.Substring(index + 10), '<'); Double a = Convert.ToDouble(temp); // culture hatasi a = (((a - 90) * -1) + 360) % 360; busDto.angle = a.ToString(); List <LocationDto> locationDtoList = Dao.GetLocations("Select LocationName,Lat,Lon From Locations"); busDto.nextLocation = GetLocationNext(locationDtoList, busDto); list.Add(busDto); } return(list); }