Exemplo n.º 1
0
 public static Location GetMidLocation(Location loc1, Location loc2)
 {
     //TODO: proper conversion.
     return(new Location((loc1.Latitude + loc2.Latitude) / 2, (loc1.Longitude + loc2.Longitude) / 2));
 }
        // This is the callback method for the CalculateRoute request.
        private void routeService_CalculateRouteCompleted(object sender, RouteService.CalculateRouteCompletedEventArgs e)
        {

            RouteResponse routeResponse = e.Result;

            // If the route calculate was a success and contains a route, then draw the route on the map.
            if (routeResponse.ResponseSummary.StatusCode != RouteService.ResponseStatusCode.Success)
            {
                //outString = "error routing ... status <" + e.Result.ResponseSummary.StatusCode.ToString() + ">";
            }
            else if (0 == e.Result.Result.Legs.Count)
            {
                //outString = "Cannot find route";
            }
            else
            {

                Color routeColor = Colors.Blue;
                SolidColorBrush routeBrush = new SolidColorBrush(routeColor);
                //outString = "Found route ... coloring route";
                //ToOutput.Foreground = routeBrush;
                MapPolyline routeLine = new MapPolyline();
                routeLine.Locations = new LocationCollection();
                routeLine.Stroke = routeBrush;
                routeLine.Opacity = 0.65;
                routeLine.StrokeThickness = 5.0;
                foreach (RouteService.Location p in routeResponse.Result.RoutePath.Points)
                {
                    routeLine.Locations.Add(new MapControl.Location(p.Latitude, p.Longitude));
                }
                RouteLayer.Children.Add(routeLine);
                LocationRect rect = new LocationRect(routeLine.Locations[0], routeLine.Locations[routeLine.Locations.Count - 1]);

                foreach (RouteService.ItineraryItem itineraryItem in e.Result.Result.Legs[0].Itinerary)
                {
                    Ellipse point = new Ellipse();
                    point.Width = 10;
                    point.Height = 10;
                    point.Fill = new SolidColorBrush(Colors.Red);
                    point.Opacity = 0.65;
                    Microsoft.Maps.MapControl.Location location = new Microsoft.Maps.MapControl.Location(itineraryItem.Location.Latitude, itineraryItem.Location.Longitude);
                    MapLayer.SetPosition(point, location);
                    MapLayer.SetPositionOrigin(point, PositionOrigin.Center);
                    point.Tag = itineraryItem;
                    point.MouseEnter += MyMap_MouseEnter;
                    point.MouseLeave += MyMap_MouseLeave;

                    RouteLayer.Children.Add(point);
                }

                MyMap.SetView(rect);
            }
        }