/// <summary> /// 这是查询的方法 /// </summary> /// <param name="dgv"></param> /// <param name="where"></param> public void SourceSearch(DataGridView dgv, string lb, string where) { List <BillIndex> bi = new List <BillIndex>(); switch (lb) { case "目的港": bi = new AimService().GetReocrdBySearch(where); break; case "来源": bi = new SourceService().GetReocrdBySearch(where); break; case "流向": bi = new DirectionService().GetReocrdBySearch(where); break; case "发往地": bi = new SendPlaceService().GetReocrdBySearch(where); break; } dgv.Rows.Clear(); foreach (BillIndex item in bi) { int index = dgv.Rows.Add(); dgv.Rows[index].Cells["dgvShipListID"].Value = item.ID; dgv.Rows[index].Cells["dgvShipListName"].Value = item.Title; dgv.Rows[index].Cells["dgvShipListDate"].Value = item.Reg_Date.ToString("yyyy-MM-dd"); } }
static void Main(string[] args) { var directionService = new DirectionService(new DrivingMode()); Console.WriteLine(directionService.GetDirection()); Console.WriteLine(directionService.GetEta()); }
private static RouteInfo GetRoute(Map map, InputOption inputOption) { ISearchAlgorithm algorithm = new DijkstraSearch(); var directionService = new DirectionService(algorithm, inputOption); return(directionService.PrepareRouteInfoFrom(map)); }
public static DistanceMatrixResponse DistanceMatrix(DistanceMatrixRequest request) { if (request.WaypointsDestination.Count < 10) { DistanceMatrixResponse response = new DistanceMatrixService().GetResponse(request); return(response); } else { List <DistanceMatrixResponse> tempList = new List <DistanceMatrixResponse>(); DirectionService ds = new DirectionService(); DirectionRequest dr; DirectionResponse dre; DistanceMatrixRequest _request; DistanceMatrixResponse _response; for (int i = 0; i < request.WaypointsDestination.Count; i++) { for (int j = 0; j < request.WaypointsDestination.Count; j++) { //_request = new DistanceMatrixRequest() //{ // WaypointsOrigin = new List<Location>() { request.WaypointsOrigin[i], request.WaypointsOrigin[j] }, // WaypointsDestination = new List<Location> { request.WaypointsDestination[i], request.WaypointsDestination[j] }, // Mode = TravelMode.driving, // Units = Units.metric //}; //_response = new DistanceMatrixService().GetResponse(_request); //tempList.Add(_response); dr = new DirectionRequest() { Origin = new Location("Kraków"), Destination = new Location("Limanowa") }; //DirectionRequest directionsRequest = new DirectionRequest() //{ // Origin = "Surrey, UK", // Destination = "London, UK", //} //DirectionResponse directionsResponse = GoogleMapsApi.GoogleMaps.Directions.Query(directionsRequest); dre = ds.GetResponse(dr); } } //var temp = ds.GetResponse(DirectionRequest request); //ds.GetResponse } //DistanceMatrixRequest request; return(null); }
// If locationToCompare is "ahead" or equal rank of locationBase, return true, else false // "Ahead" being defined as closer to relative end of board while being in same file public bool IsAhead(Vector2 locationBase, Vector2 locationToCompare, PlayerColor playerColor) { return(locationBase == locationToCompare || (locationBase.x == locationToCompare.x && (DirectionService.CalcDirection(playerColor) == Direction.UP ? locationBase.y <= locationToCompare.y : locationBase.y >= locationToCompare.y))); }
public void CreatePiece( PlayerColor playerOwner, PieceType front, PieceType back, PieceSide side, int fileNum, int rankNum) { var piece = prefabsDictionary.Instantiate("Piece"); var pieceImpl = piece.GetComponent <PieceImpl>(); var pieceLocationMoveImpl = piece.GetComponent <PieceLocationMoveImpl>(); var pieceHighlightOwnerImpl = piece.GetComponent <PieceHighlightOwnerImpl>(); entityFactory.BuildEntity <PieceED>(piece.GetInstanceID(), piece.GetComponents <IImplementor>()); pieceImpl.Front = front; pieceImpl.Back = back; pieceImpl.PieceType = side == PieceSide.FRONT ? front : back; pieceImpl.Direction = DirectionService.CalcDirection(playerOwner); pieceHighlightOwnerImpl.PlayerColor = playerOwner; Vector2 location = CommonService.CalcTransformPosition(fileNum, rankNum); piece.transform.position = new Vector3(location.x, location.y, 1); pieceLocationMoveImpl.Location = new Vector2(fileNum, rankNum); pieceHighlightOwnerImpl.PlayChangeColor = true; }
public MapRoute GetRoute(PointLatLng start, PointLatLng end, bool avoidHighways, bool walkingMode, int zoom) { MapRoute route = null; var from = new LatLng(start.Lat, start.Lng); var to = new LatLng(end.Lat, end.Lng); var direcrtionsRequest = new DirectionRequest() { Origin = from, Destination = to, Sensor = false, Mode = walkingMode ? TravelMode.walking : TravelMode.driving }; var directionService = new DirectionService(); var directionsResponse = directionService.GetResponse(direcrtionsRequest); if (directionsResponse.Status == ServiceResponseStatus.Ok) { if (directionsResponse.Routes.Any()) { var directionsRoute = directionsResponse.Routes[0]; // TODO var pathPoints = AssembleHQPolyline(directionsRoute); var pnts = (from p in pathPoints select new PointLatLng(p.Latitude, p.Longitude)).ToList(); route = new MapRoute(pnts, directionsRoute.Summary); } } return(route); }
public void PrepareRouteInfo_ShouldReturn_RoutePlan_For_FourStations_In_DiamondShape() { _harborStation.NearestToStart = _bishanStation; _bishanStation.NearestToStart = _sengkangStation; _kovanStation.NearestToStart = _sengkangStation; _sengkangStation.AddLine("NE"); _sengkangStation.AddLine("CC"); _bishanStation.AddLine("CC"); _kovanStation.AddLine("NE"); _harborStation.AddLine("NE"); _harborStation.AddLine("CC"); _algorithm.Setup(a => a.FillShortestPath(It.IsAny <List <Station> >(), It.IsAny <InputOption>())) .Returns(new List <Station> { _harborStation, _kovanStation, _bishanStation, _sengkangStation, }); var direction = new DirectionService(_algorithm.Object, new InputOption { Start = _sengkangStation.StationName, End = _harborStation.StationName }); var routeInfo = direction.PrepareRouteInfoFrom(new Map()); routeInfo.Journey.Should().NotBeEmpty() .And.HaveCount(2) .And.ContainMatch($"*{_sengkangStation.StationName}*") .And.ContainMatch($"*{_bishanStation.StationName}*") .And.ContainMatch($"*{_harborStation.StationName}*"); }
public async Task <ICollection <AddressAM> > GetNearestAddresses(AddressKind kind, Coordinate originCoordinate, double distance = 500, int maxResultCount = 5) { var coordinateBounds = await DirectionService.GetCoordinateBounds(originCoordinate, distance); var domainAddresses = await DomainAddressService.GetByCoordinateBounds( kind, coordinateBounds.MinLatitude, coordinateBounds.MinLongitude, coordinateBounds.MaxLatitude, coordinateBounds.MaxLongitude); var nearestDomainAddresses = new List <Address>(); if (domainAddresses.Any()) { var nearestCoordinates = await DirectionService.GetNearestCoordinates(originCoordinate, domainAddresses.Select(a => a.ToCoordinate()), maxResultCount); foreach (var coordinate in nearestCoordinates) { var domainAddress = domainAddresses.First(a => a.Latitude.Equals(coordinate.Latitude) && a.Longitude.Equals(coordinate.Longitude)); nearestDomainAddresses.Add(domainAddress); } } return(FromDomainAddresses(nearestDomainAddresses)); }
public override void _PhysicsProcess(float delta) { var d = 2f; if (_isBeingKnockedback) { if (LinearVelocity.Length() <= d) { _isBeingKnockedback = false; } else { return; } } if (!isChasing()) { return; } try { var toTarget = GlobalPosition.DirectionTo(_chasing.GlobalPosition); LinearVelocity = toTarget.Normalized() * 100; PlayAnimation(DirectionService.VelocityToDirection(LinearVelocity)); } catch (ObjectDisposedException e) { _chasing = null; } }
public void GetRoute_NightTime_Involving_DT_In_Middle() { var rawRecords = new List <RawStationData> { new RawStationData { StationCode = "NE1", StationName = "SengKang", OpeningDate = string.Empty }, new RawStationData { StationCode = "NE2", StationName = "Kovan", OpeningDate = string.Empty }, new RawStationData { StationCode = "NE3", StationName = "Serangoon", OpeningDate = string.Empty }, new RawStationData { StationCode = "NE4", StationName = "BoonKeng", OpeningDate = string.Empty }, new RawStationData { StationCode = "DT1", StationName = "Lorang", OpeningDate = string.Empty }, new RawStationData { StationCode = "DT2", StationName = "Serangoon", OpeningDate = string.Empty }, new RawStationData { StationCode = "DT3", StationName = "Bishan", OpeningDate = string.Empty }, new RawStationData { StationCode = "EW1", StationName = "Bugis", OpeningDate = string.Empty }, new RawStationData { StationCode = "EW2", StationName = "Bishan", OpeningDate = string.Empty }, new RawStationData { StationCode = "EW3", StationName = "Katib", OpeningDate = string.Empty }, new RawStationData { StationCode = "EW4", StationName = "Lavender", OpeningDate = string.Empty }, }; var map = new Map(rawRecords).LinkStations(); var start = new Station("Lavender"); var end = new Station("SengKang"); ISearchAlgorithm algorithm = new DijkstraSearch(); var directionService = new DirectionService(algorithm, new InputOption { Start = start.StationName, End = end.StationName, StartTime = new DateTime(2021, 3, 5, 23, 40, 00) }); var routeInfo = directionService.PrepareRouteInfoFrom(map); Assert.IsTrue(routeInfo.JourneyTitle.Contains("\"Not\" possible"), $"Was : {routeInfo.JourneyTitle}"); Assert.IsEmpty(routeInfo.Route); Assert.IsEmpty(routeInfo.StationsTraveled); Assert.IsEmpty(routeInfo.Journey); }
public void GetResultForDirections_ex1() { // expectations var expectedStatus = ServiceResponseStatus.Ok; var expectedRoutesCount = 1; var expectedEndAddress = "Montreal, QC, Canada"; var expectedEndLocation = new LatLng(45.508570, -73.553770); var expectedStartAddress = "Toronto, ON, Canada"; var expectedStartLocation = new LatLng(43.653310, -79.382770); var expectedBounds = new Viewport( northEast: new LatLng(45.51048, -73.55332), southWest: new LatLng(43.65331, -79.38373) ); var expectedDistance = new ValueText() { Text = "542 km", Value = "542382" }; var expectedDuration = new ValueText() { Text = "5 hours 27 mins", Value = "19608" }; var expectedSteps = 13; var expectedSummary = "ON-401 E"; // test var request = new DirectionRequest(); request.Origin = "Toronto"; request.Destination = "Montreal"; request.Sensor = false; var response = new DirectionService().GetResponse(request); // asserts Assert.AreEqual(expectedStatus, response.Status, "Status"); Assert.AreEqual(expectedRoutesCount, response.Routes.Length, "ResultCount"); var currentLeg = response.Routes[0].Legs[0]; Assert.That(expectedStartAddress, Is.EqualTo(currentLeg.StartAddress), "Leg.StartAddress"); Assert.That(expectedStartLocation, Is.EqualTo(currentLeg.StartLocation).Using(LatLngComparer.Within(0.000001f)), "Leg.StartLocation"); Assert.That(expectedEndAddress, Is.EqualTo(currentLeg.EndAddress), "Leg.EndAddress"); Assert.That(expectedEndLocation, Is.EqualTo(currentLeg.EndLocation).Using(LatLngComparer.Within(0.000001f)), "Leg.EndLocation"); Assert.That(expectedDistance, Is.EqualTo(currentLeg.Distance).Using(new ValueTextComparer(StringComparer.InvariantCultureIgnoreCase))); Assert.That(expectedDuration, Is.EqualTo(currentLeg.Duration).Using(new ValueTextComparer(StringComparer.InvariantCultureIgnoreCase))); Assert.That(expectedSteps, Is.EqualTo(currentLeg.Steps.Count()), "Leg.Steps"); Assert.That(expectedSummary, Is.EqualTo(response.Routes[0].Summary), "Route.Summary"); }
public RouteContext(DirectionService directionService) { this.directionService = directionService; RegisteredRoutes = new Dictionary <string, Model.Route>(); MultiPoint locations = new MultiPoint(new[] { new Point(8.681495, 49.41461), new Point(8.686507, 49.41943), new Point(8.687872, 49.420318) }); DefaultRoute = directionService.GetRoute(locations); RegisteredRoutes.Add("", DefaultRoute); }
private void AddDirectionService() { var directionHelper = ServiceProvider.GetService <DirectionHelper>(); var player = GameObject; var service = new DirectionService(player.transform, directionHelper); Services.Add(service); }
public async Task <RouteAM> GetRoute(AddressAM rootAddress, WaypointsAM waypoints) { var rootCoordinate = rootAddress.ToCoordinate(); var waypointsCoordinate = waypoints.Points.Select(p => p.ToCoordinate()); var externalRoute = await DirectionService.GetRoute(rootCoordinate, rootCoordinate, waypointsCoordinate); var result = await FromExternalRoute(rootAddress, rootAddress, waypoints, externalRoute); return(result); }
public void SetPiecePlayerOwner(PieceEV pieceEV, PlayerColor playerOwner, IEntitiesDB entitiesDB) { Direction newDirection = DirectionService.CalcDirection(playerOwner); entitiesDB.ExecuteOnEntity( pieceEV.ID, (ref PieceEV pieceToChange) => { pieceToChange.PlayerOwner.PlayerColor = playerOwner; pieceToChange.Piece.Direction = newDirection; }); }
public void PartialMatchTest() { // invalid address results in partial match var request = new DirectionRequest { Origin = new Location("410 Beeeeeechwood Rd, NJ 07450"), Destination = new Location("204 Powell Ave, CA 94523") }; var response = new DirectionService().GetResponse(request); Assert.True(response.Waypoints.Any(wp => wp.PartialMatch)); }
public CustomersController(ApplicationDbContext context, DirectionService directions, IRepositoryWrapper repo, FlightService flightService, ITSAWaitTimesService tsaWaitTimesService) { _tsaWaitTimesService = tsaWaitTimesService; _directions = directions; _tsaWaitTimesService = tsaWaitTimesService; _context = context; _repo = repo; _flightService = flightService; }
public void PrepareRouteInfo_ShouldReturn_SingleStation_In_Plan_For_SameStations_As_StartAndEnd() { _kovanStation.NearestToStart = _sengkangStation; var direction = new DirectionService(_algorithm.Object, new InputOption { Start = _sengkangStation.StationName, End = _sengkangStation.StationName }); var routeInfo = direction.PrepareRouteInfoFrom(new Map()); routeInfo.Journey.Should().BeEmpty() .And.HaveCount(0); }
static async Task <DirectionResponse> GetDirectionsOrThrow(string apiKey, DirectionRequest request) { // NOTE not the same as this class DirectionService service = new DirectionService(new GoogleSigned(apiKey)); DirectionResponse response = await service.GetResponseAsync(request); if (response.Status != ServiceResponseStatus.Ok) { throw new ApplicationException("Google Maps API access failed: " + $"({response.Status}) - message: {response.ErrorMessage}"); } return(response); }
public static void Behavioral_StateDemo2() { //This was with the problem approach: //var directionService = new DirectionService(); //directionService.setTravelMode(TravelMode.BICYCLING); //directionService.getEta(); //directionService.getDirection(); // using the state pattern: var service = new DirectionService(new Walking()); service.GetEta(); service.GetDirection(); Console.WriteLine(service.GetTravelMode()); }
public void Empty_address() { // expectations var expectedStatus = ServiceResponseStatus.ZeroResults; // test var request = new DirectionRequest(); request.Sensor = false; request.Origin = ""; var response = new DirectionService().GetResponse(request); // asserts Assert.AreEqual(expectedStatus, response.Status); }
public Task <DirectionResponse> GetDuration(Coordinate origins, Coordinate destination, TravelMode travelMode) { var request = new DirectionRequest() { Origin = new Location(origins.ToString()), Destination = new Location(destination.ToString()), Mode = travelMode, Language = "ru-RU", Sensor = false, ApiKey = "AIzaSyBn_9_tGXpdsLRM0P5utPbIZH8CT3q42Ow" }; var directionService = new DirectionService(); var responceTask = GetResponceResult <DirectionResponse>(directionService.GetRequestUriWithBaseUri(request).ToString()); responceTask.ConfigureAwait(false); return(responceTask); }
public void GetRoute_WithOutTimeFactor() { var rawRecords = new List <RawStationData> { new RawStationData { StationCode = "NE1", StationName = "SengKang", OpeningDate = string.Empty }, new RawStationData { StationCode = "NE2", StationName = "Kovan", OpeningDate = string.Empty }, new RawStationData { StationCode = "NE3", StationName = "Serangoon", OpeningDate = string.Empty }, new RawStationData { StationCode = "NE4", StationName = "BoonKeng", OpeningDate = string.Empty }, new RawStationData { StationCode = "CC1", StationName = "Lorang", OpeningDate = string.Empty }, new RawStationData { StationCode = "CC2", StationName = "Serangoon", OpeningDate = string.Empty }, new RawStationData { StationCode = "CC3", StationName = "Bishan", OpeningDate = string.Empty }, }; var map = new Map(rawRecords).LinkStations(); var start = new Station("SengKang"); var end = new Station("Bishan"); ISearchAlgorithm algorithm = new DijkstraSearch(); var directionService = new DirectionService(algorithm, new InputOption { Start = start.StationName, End = end.StationName }); var routeInfo = directionService.PrepareRouteInfoFrom(map); Assert.IsTrue(routeInfo.JourneyTitle.Contains(start.StationName), $"Was : {start.StationName}"); Assert.IsNotEmpty(routeInfo.Route); Assert.IsTrue(routeInfo.StationsTraveled.Contains("4"), $"Was : {routeInfo.StationsTraveled}"); Assert.IsNotEmpty(routeInfo.Journey); }
public void PrepareRouteInfo_ShouldReturn_RoutePlan_For_TwoStations() { _kovanStation.NearestToStart = _sengkangStation; _kovanStation.AddLine("NE"); _sengkangStation.AddLine("NE"); var direction = new DirectionService(_algorithm.Object, new InputOption { Start = _sengkangStation.StationName, End = _kovanStation.StationName }); var routeInfo = direction.PrepareRouteInfoFrom(new Map()); routeInfo.Journey.Should().NotBeEmpty() .And.HaveCount(1) .And.ContainMatch($"*{_sengkangStation.StationName}*") .And.ContainMatch($"*{_kovanStation.StationName}*"); }
public object Get(Route route) { var directionRequest = new DirectionRequest(); directionRequest.Language = "ru-RU"; directionRequest.Origin = new Location(route.Origination); directionRequest.Destination = new Location(route.Destination); directionRequest.Region = "Беларусь"; directionRequest.Sensor = false; DirectionService service = new DirectionService(); var response = service.GetResponse(directionRequest); return(new RouteResponse { Route = response.Routes[0] }); }
public void Setup() { //Given _service = new DirectionService(); _roverPositionModel = new RoverPositionModel { Direction = Direction.North, X = 1, Y = 1 }; _directionService = new Dictionary <Direction, IRotateService> { { Direction.North, new RotateNorthService() }, { Direction.South, new RotateSouthService() }, { Direction.West, new RotateWestService() }, { Direction.East, new RotateEastService() } }; }
/// <summary> /// Computes a series of driving routes from the origin, through each waypoint (in order), /// and to the destination. The first polyline corresponds to the route from the origin to the /// first waypoint, and the last polyline corresponds to the route from the last waypoint /// to the destination. If <paramref name="wayPoints"/> is empty, this is equivalent /// to <see cref="ComputeRoute(GeoCoordinates, GeoCoordinates)"/>. Will return null /// if no route is found. /// </summary> /// <exception cref="ApiAccessException">Thrown if underlying API (e.g. Google Maps) returns an error.</exception> /// <returns>A list of routes making up the journey from the origin through the waypoints to the destination. Returns /// null if no route is found.</returns> /// <param name="origin">Origin.</param> /// <param name="destination">Destination.</param> /// <param name="wayPoints">Way points.</param> static IEnumerable <GeoPolyline> ComputeRouteWithWaypoints(GeoCoordinates origin, GeoCoordinates destination, IEnumerable <GeoCoordinates> wayPoints) { List <GeoCoordinates> allWaypoints = wayPoints.ToList(); if (allWaypoints.Count == 0) { var route = ComputeRoute(origin, destination); if (route == null) { return(null); } return(new List <GeoPolyline> { route }); } var request = new DirectionRequest { Origin = origin.ToGoogleLocation(), Destination = destination.ToGoogleLocation(), Waypoints = allWaypoints.Select((pt) => (Location)pt.ToGoogleLocation()).ToList() }; var response = new DirectionService().GetResponse(request); if (response.ErrorMessage != null) { throw new ApiAccessException("Google Directions API failed with: " + response.ErrorMessage); } if (response.Routes.Length == 0) { return(null); } return(response.Routes[0].Legs .Select((leg) => leg.Steps) .Select((stepArray) => GeoPolyline.Join(stepArray.Select((step) => step.Polyline.ToGeo())))); }
public PathRequestResponce GetBestPath(string destination, string travelMode) { var request = new Google.Maps.Direction.DirectionRequest(); string parsedOrigin = GetExactParsedLocation(string.Join(", ", new string[] { "Universytetska street", CITY })); string parsedDestination = GetExactParsedLocation(string.Join(", ", new string[] { destination, CITY })); request.Origin = new Google.Maps.Location(parsedOrigin); request.Destination = new Google.Maps.Location(parsedDestination); request.Mode = ParseTravelMode(travelMode); request.Sensor = false; request.Language = "en"; request.Region = "UA"; var response = new DirectionService().GetResponse(request); return(new PathRequestResponce { PathInsructions = ParseRoute(response.Routes[0].Legs[0].Steps) }); }
/// <summary> /// Computes a driving route between two points. This may return null if /// a route could not be found. /// </summary> /// <exception cref="ApiAccessException">Thrown if underlying API (e.g. Google Maps) returns an error.</exception> /// <returns>The route.</returns> /// <param name="origin">Origin.</param> /// <param name="destination">Destination.</param> static GeoPolyline ComputeRoute(GeoCoordinates origin, GeoCoordinates destination) { var request = new DirectionRequest { Origin = origin.ToGoogleLocation(), Destination = destination.ToGoogleLocation() }; var response = new DirectionService().GetResponse(request); if (response.ErrorMessage != null) { throw new ApiAccessException("Google Directions API failed with: " + response.ErrorMessage); } if (response.Routes.Length == 0) { // This can happen if a route is not found. return(null); } return(response.Routes[0].OverviewPolyline.ToGeo()); }