private static void DeserializeJSONObjects(JObject jsonFile) { //is only returning distance&duration between first two waypoints //JToken resourceToken = jsonFile["resourceSets"][0]["resources"][0]["routeLegs"][0]; //routeLegs = JsonConvert.DeserializeObject<RouteLeg>(resourceToken.ToString()); JToken resourceToken = jsonFile["resourceSets"][0]["resources"][0]; _route = JsonConvert.DeserializeObject <BingMapsRESTService.Common.JSON.Route>(resourceToken.ToString()); }
private void Route(BingMapsRESTService.Common.JSON.Response r) { if (r != null && r.ResourceSets != null && r.ResourceSets.Length > 0 && r.ResourceSets[0].Resources != null && r.ResourceSets[0].Resources.Length > 0) { BingMapsRESTService.Common.JSON.Route route = r.ResourceSets[0].Resources[0] as BingMapsRESTService.Common.JSON.Route; double[][] routePath = route.RoutePath.Line.Coordinates; LocationCollection locs = new LocationCollection(); for (int i = 0; i < routePath.Length; i++) { if (routePath[i].Length >= 2) { locs.Add(new Microsoft.Maps.MapControl.WPF.Location(routePath[i][0], routePath[i][1])); } } MapPolyline routeLine = new MapPolyline() { Locations = locs, Stroke = new SolidColorBrush(Colors.Blue), StrokeThickness = 5 }; ParcelMap.Children.Add(routeLine); ParcelMap.SetView(locs, new Thickness(30), 0); var parcelAddViewModel = (ParcelAddViewModel)DataContext; parcelAddViewModel.ParcelDistance = route.TravelDistance; parcelAddViewModel.ParcelDuration = route.TravelDuration; } }