Ejemplo n.º 1
0
        private async Task <BingRouteResource> ComputeRoute(BingGeocodePoint start, BingGeocodePoint end)
        {
            RestRequest request = new RestRequest($"Routes/Driving", Method.GET);

            request.AddParameter("wp.0", $"{start.coordinates[0]},{start.coordinates[1]}", ParameterType.QueryString);
            request.AddParameter("wp.1", $"{end.coordinates[0]},{end.coordinates[1]}", ParameterType.QueryString);
            request.AddParameter("routeAttributes", "routePath", ParameterType.QueryString);
            request.AddParameter("distanceUnit", "mi", ParameterType.QueryString);
            request.AddParameter("tl", _config.BingTolerance.ToString(), ParameterType.QueryString);
            request.AddParameter("key", _config.BingKey, ParameterType.QueryString);

            var result = await _bingClient.ExecuteTaskAsync <string>(request);

            if (!result.IsSuccessful)
            {
                throw new Exception($"Failed to find address with error {result.StatusCode}");
            }

            string            json = result.Data;
            JObject           jobj = JsonConvert.DeserializeObject <JObject>(json);
            BingRouteResult   obj  = jobj.ToObject <BingRouteResult>();
            BingRouteResource res  = obj.resourceSets[0].resources[0];

            return(res);
        }
Ejemplo n.º 2
0
        void CalculateRoute(BingTravelMode mode)
        {
            if (isBusy)
            {
                return;
            }
            isBusy = true;
            var waypoints    = new[] { new RouteWaypoint(StartingAddress, StartingLocation), new RouteWaypoint(DestinationAddress, DestinationLocation) };
            var unit         = DistanceMeasureUnit.Mile;
            var optimization = BingRouteOptimization.MinimizeTime;

            RouteService.CalculateRouteAsync(waypoints, unit, optimization, mode).ContinueWith(t => {
                if (t.Result.ResultCode == RequestResultCode.Success && t.Result.RouteResults.Count > 0)
                {
                    BingRouteResult route = t.Result.RouteResults.First();
                    if (route.Legs.Count > 0)
                    {
                        BingRouteLeg leg       = route.Legs.First();
                        IsWalkingAvailable     = (leg.Distance > maximumWalkingDistance) ? false : true;
                        GeoPoint startLocation = leg.Itinerary.First().Location;
                        GeoPoint endLocation   = leg.Itinerary.Last().Location;
                        CenterPoint            = new GeoPoint((startLocation.Latitude + endLocation.Latitude) / 2, (startLocation.Longitude + endLocation.Longitude) / 2);
                        ActiveItinerary        = leg.Itinerary.Select(item => new ItineraryItemViewModel(item)).ToList();
                    }
                }
                isBusy = false;
            }, TaskScheduler.FromCurrentSynchronizationContext());
        }
Ejemplo n.º 3
0
 void ExtractItineraryItems(BingRouteResult result)
 {
     ItineraryItems.Clear();
     foreach (BingRouteLeg leg in result.Legs)
     {
         foreach (BingItineraryItem item in leg.Itinerary)
         {
             ItineraryItems.Add(item);
         }
     }
 }
Ejemplo n.º 4
0
 public void ProcessRouteResult(BingRouteResult result)
 {
     if (result != null)
     {
         ExtractItineraryItems(result);
         routePath = result.RoutePath;
     }
     else
     {
         routePath = null;
     }
     CalculatePathDistance();
 }