Ejemplo n.º 1
0
 /// <summary>
 /// Populates the page with content passed during navigation. Any saved state is also
 /// provided when recreating a page from a prior session.
 /// </summary>
 /// <param name="sender">
 /// The source of the event; typically <see cref="NavigationHelper"/>.
 /// </param>
 /// <param name="e">Event data that provides both the navigation parameter passed to
 /// <see cref="Frame.Navigate(Type, Object)"/> when this page was initially requested and
 /// a dictionary of state preserved by this page during an earlier
 /// session.  The state will be null the first time a page is visited.</param>
 private void NavigationHelper_LoadState(object sender, LoadStateEventArgs e)
 {
     // TODO: Create an appropriate data model for your problem domain to replace the sample data.
 }
 /// <summary>
 /// Populates the page with content passed during navigation. Any saved state is also
 /// provided when recreating a page from a prior session.
 /// </summary>
 /// <param name="sender">
 /// The source of the event; typically <see cref="NavigationHelper"/>.
 /// </param>
 /// <param name="e">Event data that provides both the navigation parameter passed to
 /// <see cref="Frame.Navigate(Type, Object)"/> when this page was initially requested and
 /// a dictionary of state preserved by this page during an earlier
 /// session.  The state will be null the first time a page is visited.</param>
 private void NavigationHelper_LoadState(object sender, LoadStateEventArgs e)
 {
 }
        /// <summary>
        /// Populates the page with content passed during navigation. Any saved state is also
        /// provided when recreating a page from a prior session.
        /// </summary>
        /// <param name="sender">
        /// The source of the event; typically <see cref="NavigationHelper"/>.
        /// </param>
        /// <param name="e">Event data that provides both the navigation parameter passed to
        /// <see cref="Frame.Navigate(Type, Object)"/> when this page was initially requested and
        /// a dictionary of state preserved by this page during an earlier
        /// session.  The state will be null the first time a page is visited.</param>
        private async void NavigationHelper_LoadState(object sender, LoadStateEventArgs e)
        {
            // start at Grand Central Station
            BasicGeoposition startLocation = new BasicGeoposition();
            startLocation.Latitude = 40.7517;
            startLocation.Longitude = -073.9766;
            Geopoint startPoint = new Geopoint(startLocation);

            // end at Central Park
            BasicGeoposition endLocation = new BasicGeoposition();
            endLocation.Latitude = 40.7669;
            endLocation.Longitude = -073.9790;
            Geopoint endPoint = new Geopoint(endLocation);

            // Get the route between the points.
            MapRouteFinderResult routeResult =
            await MapRouteFinder.GetWalkingRouteAsync(
                startPoint,
                endPoint);

            if (routeResult.Status == MapRouteFinderStatus.Success)
            {
                // Display summary info about the route.
                tbTurnByTurn.Inlines.Add(new Run()
                {
                    Text = resourceLoader.GetString("Summary")
                });

                tbTurnByTurn.Inlines.Add(new LineBreak());
                tbTurnByTurn.Inlines.Add(new LineBreak());

                tbTurnByTurn.Inlines.Add(new Run()
                {
                    Text = resourceLoader.GetString("TotalTime") + " = " 
                        + routeResult.Route.EstimatedDuration.TotalMinutes.ToString("F1")
                });
                tbTurnByTurn.Inlines.Add(new LineBreak());
                tbTurnByTurn.Inlines.Add(new Run()
                {
                    Text = resourceLoader.GetString("TotalLength") + " = "
                        + (routeResult.Route.LengthInMeters / 1000).ToString("F1")
                });
                tbTurnByTurn.Inlines.Add(new LineBreak());
                tbTurnByTurn.Inlines.Add(new LineBreak());

                // Display the directions.
                tbTurnByTurn.Inlines.Add(new Run()
                {
                    Text = resourceLoader.GetString("Directions") 
                });

                tbTurnByTurn.Inlines.Add(new LineBreak());
                tbTurnByTurn.Inlines.Add(new LineBreak());

                // loop through the legs and maneuvers
                foreach (MapRouteLeg leg in routeResult.Route.Legs)
                {
                    foreach (MapRouteManeuver maneuver in leg.Maneuvers)
                    {
                        tbTurnByTurn.Inlines.Add(new Run()
                        {
                            Text = maneuver.InstructionText
                        });

                        tbTurnByTurn.Inlines.Add(new LineBreak());
                        tbTurnByTurn.Inlines.Add(new LineBreak());
                    }

                }

                // Use the route to initialize a MapRouteView.
                MapRouteView viewOfRoute = new MapRouteView(routeResult.Route);
                viewOfRoute.RouteColor = Colors.Blue;
                viewOfRoute.OutlineColor = Colors.Blue;

                // Add the new MapRouteView to the Routes collection
                // of the MapControl.
                MapwithDrivingRoute.Routes.Add(viewOfRoute);
                
                // Fit the MapControl to the route.
                await MapwithDrivingRoute.TrySetViewBoundsAsync(
                    routeResult.Route.BoundingBox,
                    null,
                    Windows.UI.Xaml.Controls.Maps.MapAnimationKind.Bow);

            }
            else
            {
                // Tell the user to try again.
                string message = this.resourceLoader.GetString("NoRoute");
                string title = this.resourceLoader.GetString("NoRouteTitle");
                MessageDialog messageDialog = new MessageDialog(message, title);
                await messageDialog.ShowAsync();
            }

        }