Exemple #1
0
 static private async void wc_DownloadStringCompleted(object sender, DownloadStringCompletedEventArgs e)
 {
     var query = new RouteQuery();
     var data = e.Result;
     var json = JsonConvert.DeserializeObject<Maproute>(data);
     if (json.elements.Count > 0)
     {
         int i = 0;
         GeoCoordinate[] geo = new GeoCoordinate[json.elements.Count];
         String[] busstops = new String[json.elements.Count];
         while (i < json.elements.Count)
         {
             geo[i] = new GeoCoordinate(json.elements[i].lat, json.elements[i].lon);
             i++;
         }
         query.Waypoints = geo;
         query.TravelMode = TravelMode.Driving;
         var result = await query.GetRouteAsync();
         Route myroute = result;
         maproute = new MapRoute(myroute);
         maproute.Color = Colors.Red;
        // kmap.AddRoute(maproute);
         query.Dispose();
     }
 }
Exemple #2
0
        /// <summary>
        /// Method to show Route
        /// </summary>
        private async void OnShowRoute()
        {
            this.UserLocationMarker.GeoCoordinate  = Globals.RecentLocation.Coordinate;
            this.UserLocationMarker.Visibility     = System.Windows.Visibility.Visible;
            this.RouteDirectionsPushPin.Visibility = Visibility.Visible;

            this.Map.SetView(this.UserLocationMarker.GeoCoordinate, this.userLocationMarkerZoomLevel);

            if (this.RouteDirectionsPushPin.GeoCoordinate == null || this.RouteDirectionsPushPin.Visibility == Visibility.Collapsed)
            {
                Deployment.Current.Dispatcher.BeginInvoke(() => Globals.DisplayToast(CustomMessage.MapTapHoldToShowRouteFromLocationToDestination, "basicWrap", "Info!"));
            }
            else
            {
                RouteQuery           query;
                List <GeoCoordinate> wayPoints;
                Route route;

                if (this.MapRoute != null)
                {
                    this.Map.RemoveRoute(this.MapRoute);
                }

                //await this.ShowUserLocation();

                query     = new RouteQuery();
                wayPoints = new List <GeoCoordinate>();

                wayPoints.Add(this.UserLocationMarker.GeoCoordinate);
                wayPoints.Add(this.RouteDirectionsPushPin.GeoCoordinate);

                query.Waypoints = wayPoints;

                route = await query.GetRouteAsync();

                this.MapRoute = new MapRoute(route);

                this.Map.SetView(route.BoundingBox);
                this.Map.AddRoute(this.MapRoute);

                this.ChangeMode(MapMode.Route);
            }
        }
        /// <summary>
        /// Event handler for the show route button
        /// </summary>
        /// <param name="sender">Sender of the event</param>
        /// <param name="e">Event arguments</param>
        private async void OnShowRoute(object sender, EventArgs e)
        {
            if (this.RouteDirectionsPushPin.GeoCoordinate == null || this.RouteDirectionsPushPin.Visibility == Visibility.Collapsed)
            {
                MessageBox.Show("Tap and hold somewhere in the map to show a Pushpin. After that you can show route from your location to the destination");
            }
            else
            {
                RouteQuery           query;
                List <GeoCoordinate> wayPoints;
                Route route;

                this.ShowStores(false);
                if (this.MapRoute != null)
                {
                    this.Map.RemoveRoute(this.MapRoute);
                }

                await this.ShowUserLocation();

                query     = new RouteQuery();
                wayPoints = new List <GeoCoordinate>();

                wayPoints.Add(this.UserLocationMarker.GeoCoordinate);
                wayPoints.Add(this.RouteDirectionsPushPin.GeoCoordinate);

                query.Waypoints = wayPoints;

                route = await query.GetRouteAsync();

                this.MapRoute = new MapRoute(route);

                this.Map.SetView(route.BoundingBox);
                this.Map.AddRoute(this.MapRoute);

                this.ChangeMode(MapMode.Route);
            }
        }
        /// <summary>
        /// Handles the hold gensture on the map.
        /// </summary>
        /// <param name="sender">The sender.</param>
        /// <param name="e">The <see cref="System.Windows.Input.GestureEventArgs"/> instance containing the event data.</param>
        private async void OnMapHold(object sender, System.Windows.Input.GestureEventArgs e)
        {
            var selectedDestination = theMap.ConvertViewportPointToGeoCoordinate(e.GetPosition(theMap));

            var query = new RouteQuery();
            var course = App.ViewModel.CurrentLocation.Course;
            query.InitialHeadingInDegrees = course;
            query.TravelMode = TravelMode.Walking;
            query.Waypoints = new List<GeoCoordinate> { App.ViewModel.CurrentLocation, selectedDestination };
            query.RouteOptimization = RouteOptimization.MinimizeTime;
            var result = await query.GetRouteAsync();
            App.ViewModel.DurationToDestination = result.EstimatedDuration;

            this.CreateSms();
        }
        /// <summary>
        /// Event handler for the show route button
        /// </summary>
        /// <param name="sender">Sender of the event</param>
        /// <param name="e">Event arguments</param>
        private async void OnShowRoute(object sender, EventArgs e)
        {
            if (this.RouteDirectionsPushPin.GeoCoordinate == null || this.RouteDirectionsPushPin.Visibility == Visibility.Collapsed)
            {
                MessageBox.Show("Tap and hold somewhere in the map to show a Pushpin. After that you can show route from your location to the destination");
            }
            else
            {
                RouteQuery query;
                List<GeoCoordinate> wayPoints;
                Route route;

                this.ShowStores(false);
                if (this.MapRoute != null)
                {
                    this.Map.RemoveRoute(this.MapRoute);
                }

                await this.ShowUserLocation();

                query = new RouteQuery();
                wayPoints = new List<GeoCoordinate>();

                wayPoints.Add(this.UserLocationMarker.GeoCoordinate);
                wayPoints.Add(this.RouteDirectionsPushPin.GeoCoordinate);

                query.Waypoints = wayPoints;

                route = await query.GetRouteAsync();
                this.MapRoute = new MapRoute(route);

                this.Map.SetView(route.BoundingBox);
                this.Map.AddRoute(this.MapRoute);

                this.ChangeMode(MapMode.Route);
            }
        }
//------------------------------ Finding the bus stop if the Source is provided ---------------------------//
        
        
        public async void findbusstop(string str)
        {
            String[] busstops = new String[20];
            busstops[0] = "Tollygunge";
            busstops[1] = "Bangur Hospital";
            busstops[2] = "Rashbehari More";
            busstops[3] = "Sarat Bose Road Xing";
            busstops[4] = "Basanti Devi College";
            busstops[5] = "Gariahat";
            busstops[6] = "Bakultala P.O";
            busstops[7] = "Narkelbagan";
            busstops[8] = "Ruby";
            busstops[9] = "Vip Bazar";
            busstops[10] = "Panchannagram";
            busstops[11] = "Science City";
            busstops[12] = "Chingrighata";
            busstops[13] = "Beliaghata";
            busstops[14] = "Hyatt Regency";
            busstops[15] = "Ultadanga";
            busstops[16] = "Lake Town";
            busstops[17] = "Dum Dum Park";
            busstops[18] = "Baguihati";
            busstops[19] = "Kaikhali";

            for(int a = 0; a < 20; a++)
            {
                if(busstops[a].Equals(str))
                {
                    find = getgeoCoords(a);
                }
            }

            myposition();
            GeoCoordinate g1 = new GeoCoordinate(l1,l2);

            var query = new RouteQuery();
            query.Waypoints = new[]
            {
                g1,
                find,
            };

            query.TravelMode = TravelMode.Driving;
            var result = await query.GetRouteAsync();
            Route myroute = result;
            double dis = myroute.LengthInMeters;
            dis = dis / 1000;
            if (me2bus != null) kmap.RemoveRoute(me2bus);
            me2bus = new MapRoute(myroute);
            me2bus.Color = Colors.Orange;
            kmap.AddRoute(me2bus);
            query.Dispose();

            text1.Text = "Nearest Bus Stop : " + str;
            text1.IsReadOnly = true;
            text1.Opacity = 1;

            text2.Text = dis + " Km";
            text2.Opacity = 1;
            text2.IsReadOnly = true;

            Microsoft.Phone.Maps.Toolkit.Pushpin push3 = new Microsoft.Phone.Maps.Toolkit.Pushpin();
            push3.Content = "     Bus-Stop   ";
            push3.FontSize = 18;
            push3.GeoCoordinate = find;
            push3.Opacity = 0.7;
            push3.Background = new SolidColorBrush(Colors.Green);
            push3.Foreground = new SolidColorBrush(Colors.White);

            kmap.Layers.Remove(stopPos);
            kmap.Layers.Remove(stopPosDot);

            MapOverlay myoverlay3 = new MapOverlay();
            myoverlay3.Content = push3;
            myoverlay3.GeoCoordinate = find;
            myoverlay3.PositionOrigin = new Point(0, 1);
            stopPos = new MapLayer();
            stopPos.Add(myoverlay3);
            kmap.Layers.Add(stopPos);
            stopPosDot = ShowLocation(find);
        }
        public async void opencompletedstring(object sender, DownloadStringCompletedEventArgs e)
        {
            var myData = e.Result;
            var json = JsonConvert.DeserializeObject<MapData>(myData);
            double lat2 = json.lat;
            double lon2 = json.lon;
            int i = json.index;
            myStopPos = i;
            double distance = json.distance;
            double dis = distance / 1000;

            GeoCoordinate g1 = new GeoCoordinate(l1, l2);
            GeoCoordinate g2 = new GeoCoordinate(lat2, lon2);

            String[] busstops = new String[20];
            busstops[0] = "Tollygunge";
            busstops[1] = "Bangur Hospital";
            busstops[2] = "Rashbehari More";
            busstops[3] = "Sarat Bose Road Xing";
            busstops[4] = "Basanti Devi College";
            busstops[5] = "Gariahat";
            busstops[6] = "Bakultala P.O";
            busstops[7] = "Narkelbagan";
            busstops[8] = "Ruby";
            busstops[9] = "Vip Bazar";
            busstops[10] = "Panchannagram";
            busstops[11] = "Science City";
            busstops[12] = "Chingrighata";
            busstops[13] = "Beliaghata";
            busstops[14] = "Hyatt Regency";
            busstops[15] = "Ultadanga";
            busstops[16] = "Lake Town";
            busstops[17] = "Dum Dum Park";
            busstops[18] = "Baguihati";
            busstops[19] = "Kaikhali";

            text1.Text = "Nearest Bus Stop : " + busstops[i - 1];
            text1.IsReadOnly = true;
            text1.Opacity = 1;

            text2.Text = dis + " Km";
            text2.Opacity = 1;
            text2.IsReadOnly = true;

            var query = new RouteQuery();
            query.Waypoints = new[]
            {
                g1,
                g2,
            };

            if(me2bus!=null) kmap.RemoveRoute(me2bus);
            query.TravelMode = TravelMode.Driving;
            var result = await query.GetRouteAsync();
            Route myroute = result;
            me2bus = new MapRoute(myroute);
            me2bus.Color = Colors.Orange;
            kmap.AddRoute(me2bus);
            query.Dispose();

            kmap.Layers.Remove(stopPos);
            kmap.Layers.Remove(stopPosDot);

            Microsoft.Phone.Maps.Toolkit.Pushpin push3 = new Microsoft.Phone.Maps.Toolkit.Pushpin();
            push3.Content = "     Bus-Stop   ";
            push3.FontSize = 18;
            push3.GeoCoordinate = g2;
            push3.Opacity = 0.7;
            push3.Background = new SolidColorBrush(Colors.Green);
            push3.Foreground = new SolidColorBrush(Colors.White);

            MapOverlay myoverlay3 = new MapOverlay();
            myoverlay3.Content = push3;
            myoverlay3.GeoCoordinate = g2;
            myoverlay3.PositionOrigin = new Point(0,1);
            stopPos = new MapLayer();
            stopPos.Add(myoverlay3);
            kmap.Layers.Add(stopPos);
            stopPosDot = ShowLocation(g2);
        }
        public async void busrouteprovided()
        {
            GeoCoordinate[] geocords = new GeoCoordinate[21];
            var query = new RouteQuery();
            query.Waypoints = new GeoCoordinate[]
            {
              new GeoCoordinate(22.4946412329567,88.3455178639135), // Tollygunge
              new GeoCoordinate(22.4999830886328, 88.3450915643186),// Bangur Hospital
              new GeoCoordinate(22.5170895753413, 88.3462961913435), // Rashbehari More
              new GeoCoordinate(22.51738265698964, 88.3523637605948), // Sarat Bose Road Xing
              new GeoCoordinate(22.5188118870097, 88.3600069631226), // Basanti Devi College
              new GeoCoordinate(22.5198945865004, 88.3657370808621), // Gariahat
              new GeoCoordinate(22.5195788000248, 88.3765461665984), // Bakultala P.O
              new GeoCoordinate(22.5135787198967, 88.4000526723251), // Narkelbagan
              new GeoCoordinate(22.5139424594816, 88.401602802297), // Ruby
              new GeoCoordinate(22.5254692843552, 88.3958326617964), // Vip Bazar
              new GeoCoordinate(22.5276830738962,88.3949543528643),
              new GeoCoordinate(22.5279701507772,88.3949643141571),
              new GeoCoordinate(22.5282682684453,88.3949922057769),
              new GeoCoordinate(22.5284743741112,88.3950340432066),
              new GeoCoordinate(22.5288755431862,88.3951356483931),
              new GeoCoordinate(22.529302474133,88.3952412380968),
              new GeoCoordinate(22.5297588471342,88.3953587813519),
              new GeoCoordinate(22.5301140073377,88.3954524175043),
              new GeoCoordinate(22.5305482952574,88.3955341001052),
              new GeoCoordinate(22.541757285409, 88.398245731789),  // Science City
              new GeoCoordinate(22.5586679662571, 88.4108906215633), // Chingrighata
              new GeoCoordinate(22.5620540608442, 88.4082246754306), // Beliaghata
              new GeoCoordinate(22.5711483685549, 88.4038818437594), // Hyatt Regency
              new GeoCoordinate(22.5921224653173, 88.3944552201765), // Ultadanga
              new GeoCoordinate(22.6000509021716, 88.4068897446306), // Lake Town
              new GeoCoordinate(22.6031167221805, 88.4187243912121), // Dum Dum Park
              new GeoCoordinate(22.610301093592, 88.4278974632185), // Baguihati
              new GeoCoordinate(22.6276967999729, 88.4334427274113), // Kaikhali
            };

            query.TravelMode = TravelMode.Driving;
            var result = await query.GetRouteAsync();
            Route myroute = result;
            var maproute = new MapRoute(myroute);
            maproute.Color = Colors.Green;
            kmap.AddRoute(maproute);
            query.Dispose();
    }