コード例 #1
0
        public async Task Search()
        {
            var response = await Http.GetAsync("api/AzureMaps/GetSubscriptionKey", HttpCompletionOption.ResponseContentRead);

            if (response.IsSuccessStatusCode)
            {
                SubscriptionKey = await response.Content.ReadAsStringAsync();

                GetFastestRouteModel model = new GetFastestRouteModel()
                {
                    StartPoint = new Components.GeoCoordinates()
                    {
                        Latitude  = double.Parse(FromLatitude),
                        Longitude = double.Parse(FromLongitude)
                    },
                    EndPoint = new GeoCoordinates()
                    {
                        Latitude  = double.Parse(ToLatitude),
                        Longitude = double.Parse(ToLongitude)
                    }
                };
                response = await Http.PostAsJsonAsync <GetFastestRouteModel>("api/AzureMaps/GetFastestRoute", model);

                if (response.IsSuccessStatusCode)
                {
                    this.FastestRoute = await response.Content.ReadFromJsonAsync <GetFastestRouteModel>();

                    this.RouteStart    = this.FastestRoute.StartPoint;
                    this.RouteEnd      = this.FastestRoute.EndPoint;
                    this.PointsInRoute = this.FastestRoute.WayPoints;
                    CanRenderMap       = true;
                }
            }
        }
コード例 #2
0
        public async Task <GetFastestRouteModel> GetFastestRoute(GetFastestRouteModel model)
        {
            var fastestRoute = await this.azureMapsService.GetOptimizedRouteAsync(
                startingPoint : new PTI.Microservices.Library.Models.Shared.GeoCoordinates()
            {
                Latitude  = model.StartPoint.Latitude,
                Longitude = model.StartPoint.Longitude
            },
                finalPoint : new PTI.Microservices.Library.Models.Shared.GeoCoordinates()
            {
                Latitude  = model.EndPoint.Latitude,
                Longitude = model.EndPoint.Longitude
            },
                pointsInRoute : null);

            GetFastestRouteModel result = new GetFastestRouteModel();
            var points     = fastestRoute?.routes?.First()?.legs?.First().points;
            var startPoint = points?.First();
            var endPoint   = points?.Last();
            var wayPoints  = points?.Except(new Point[] { startPoint, endPoint });

            result.StartPoint = new GeoCoordinates()
            {
                Latitude  = startPoint.latitude,
                Longitude = startPoint.longitude
            };
            result.EndPoint = new GeoCoordinates()
            {
                Latitude  = endPoint.latitude,
                Longitude = endPoint.longitude
            };
            if (wayPoints?.Count() > 0)
            {
                result.WayPoints = wayPoints.Select(p => new GeoCoordinates
                {
                    Latitude  = p.latitude,
                    Longitude = p.longitude
                }).ToArray();
            }
            return(result);
        }