Example #1
0
        protected async override void OnNavigatedTo(NavigationEventArgs e)
        {


            part = e.Parameter as Campuses;
            heading.Text = part.City + " " + part.Name;


            BasicGeoposition startLocation = new BasicGeoposition();
            startLocation.Latitude = -25.73134;
            startLocation.Longitude = 28.21837;
            Geopoint startPoint = new Geopoint(startLocation);

            // End at the city of Seattle, Washington.
            BasicGeoposition endLocation = new BasicGeoposition();
            endLocation.Latitude = part.Latitude;
            endLocation.Longitude = part.Longitude;
            Geopoint endPoint = new Geopoint(endLocation);

            // Get the route between the points.
            MapRouteFinderResult routeResult =
                await MapRouteFinder.GetDrivingRouteAsync(
                startPoint,
                endPoint,
                MapRouteOptimization.Time,
                MapRouteRestrictions.None);

            if (routeResult.Status == MapRouteFinderStatus.Success)
            {
                // Display summary info about the route.
                tbOutputText.Inlines.Add(new Run()
                {
                    Text = "Total estimated time (minutes) = "
                        + routeResult.Route.EstimatedDuration.TotalMinutes.ToString()
                });
                tbOutputText.Inlines.Add(new LineBreak());
                tbOutputText.Inlines.Add(new Run()
                {
                    Text = "Total length (kilometers) = "
                        + (routeResult.Route.LengthInMeters / 1000).ToString()
                });
                tbOutputText.Inlines.Add(new LineBreak());
                tbOutputText.Inlines.Add(new LineBreak());

                // Display the directions.
                tbOutputText.Inlines.Add(new Run()
                {
                    Text = "DIRECTIONS"
                });
                tbOutputText.Inlines.Add(new LineBreak());

                foreach (MapRouteLeg leg in routeResult.Route.Legs)
                {
                    foreach (MapRouteManeuver maneuver in leg.Maneuvers)
                    {
                        tbOutputText.Inlines.Add(new Run()
                        {
                            Text = maneuver.InstructionText
                        });
                        tbOutputText.Inlines.Add(new LineBreak());
                    }
                }
            }
            else
            {
                tbOutputText.Text =
                    "A problem occurred: " + routeResult.Status.ToString();
            }

        }
Example #2
0
        protected async override void OnNavigatedTo(NavigationEventArgs e)
        {


           
            // Show users
           
          part = e.Parameter as Campuses;
          SQLiteAsyncConnection connection = new SQLiteAsyncConnection("institutionFinder.db");
          var users = await connection.QueryAsync<Campuses>("Select * FROM Campuses WHERE Name ='" + part.Name + "'");
            // Get users
          camp = users.FirstOrDefault();
        
            map.MapServiceToken = "yvPVkyiTloR2lug6UK3uVg";

            map.Center =
               new Geopoint(new BasicGeoposition()
               {
                   Latitude = camp.Latitude,
                   Longitude = camp.Longitude
               });
            map.ZoomLevel = 15;
            map.LandmarksVisible = true;

            MapIcon MapIcon1 = new MapIcon();
            MapIcon1.Location = new Geopoint(new BasicGeoposition()
            {

                Latitude = camp.Latitude,
                Longitude = camp.Longitude
            });
            MapIcon1.NormalizedAnchorPoint = new Point(10,10);
            MapIcon1.Title = camp.Name;
            map.MapElements.Add(MapIcon1);


            MapIcon1.Image = RandomAccessStreamReference.CreateFromUri(new Uri("ms-appx:///ViewModels/map.jpg"));
            Windows.UI.Xaml.Shapes.Ellipse fence = new Windows.UI.Xaml.Shapes.Ellipse();
           
            MapControl.SetNormalizedAnchorPoint(fence, new Point(0.5, 0.5));

            // Get a route as shown previously.
            BasicGeoposition startLocation = new BasicGeoposition();
            startLocation.Latitude = -25.73134;
            startLocation.Longitude = 28.21837;
            Geopoint startPoint = new Geopoint(startLocation);

            // End at the city of Seattle, Washington.
            BasicGeoposition endLocation = new BasicGeoposition();
            endLocation.Latitude = camp.Latitude;
            endLocation.Longitude = camp.Longitude;
            Geopoint endPoint = new Geopoint(endLocation);

            MapRouteFinderResult routeResult =
             await MapRouteFinder.GetDrivingRouteAsync(
             startPoint,
             endPoint,
             MapRouteOptimization.Time,
             MapRouteRestrictions.None);

            if (routeResult.Status == MapRouteFinderStatus.Success)
            {
                // Use the route to initialize a MapRouteView.
                MapRouteView viewOfRoute = new MapRouteView(routeResult.Route);
                viewOfRoute.RouteColor = Colors.Yellow;
                viewOfRoute.OutlineColor = Colors.Black;

                // Add the new MapRouteView to the Routes collection
                // of the MapControl.
                map.Routes.Add(viewOfRoute);

                // Fit the MapControl to the route.
                await map.TrySetViewBoundsAsync(
                    routeResult.Route.BoundingBox,
                    null,
                    Windows.UI.Xaml.Controls.Maps.MapAnimationKind.None);
            }
           
        }