Exemplo n.º 1
0
        /// <summary>
        /// Route Query completed event
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        void myRouteQuery_QueryCompleted(object sender, QueryCompletedEventArgs <Route> e)
        {
            if (e.Error == null)
            {
                Route MyRoute = e.Result;

                MapRoute MyMapRoute = new MapRoute(MyRoute);

                myMap.AddRoute(MyMapRoute);

                foreach (RouteLeg leg in MyRoute.Legs)
                {
                    foreach (RouteManeuver maneuver in leg.Maneuvers)
                    {
                        textBoxDirections.Text += maneuver.InstructionText + Environment.NewLine;
                    }
                }

                myRouteQuery.Dispose();
            }
            else
            {
                MessageBox.Show("Unable to generate route.");
            }
        }
Exemplo n.º 2
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();
     }
 }
Exemplo n.º 3
0
 private void MyQuery_QueryCompleted(object sender, QueryCompletedEventArgs <Route> e)
 {
     if (e.Error == null)
     {
         Route    MyRoute    = e.Result;
         MapRoute MyMapRoute = new MapRoute(MyRoute);
         map.AddRoute(MyMapRoute);
         map.SetView(MyRoute.BoundingBox, MapAnimationKind.Parabolic);
         MyQuery.Dispose();
     }
 }
Exemplo n.º 4
0
 void routeQuery_QueryCompleted(object sender, QueryCompletedEventArgs <Route> e)
 {
     if (null == e.Error)
     {
         Route    MyRoute    = e.Result;
         MapRoute MyMapRoute = new MapRoute(MyRoute);
         mapItineraryDetails.AddRoute(MyMapRoute);
         //length of route
         //time = route / v trung binh(hang so)
         //MessageBox.Show("Distance: " + MyMapRoute.Route.LengthInMeters.ToString());
         routeQuery.Dispose();
     }
 }
Exemplo n.º 5
0
 void MyQuery_QueryCompleted(object sender, QueryCompletedEventArgs <Route> e)
 {
     if (e.Error == null)
     {
         try
         {
             Route    MyRoute    = e.Result;
             MapRoute MyMapRoute = new MapRoute(MyRoute);
             MyMap.AddRoute(MyMapRoute);
             MyQuery.Dispose();
         }
         catch
         {
         }
     }
 }
        private void MyQuery_QueryCompleted(object sender, QueryCompletedEventArgs <Route> e)
        {
            if (e.Error == null)
            {
                Route MyRoute = e.Result;
                if (MyMapRoute != null)
                {
                    //clear last route
                    MyMap.RemoveRoute(MyMapRoute);
                }
                MyMapRoute = new MapRoute(MyRoute);
                MyMap.AddRoute(MyMapRoute);
                MyQuery.Dispose();

                //set the map view to fit the route
                LocationRectangle locationRectangle = LocationRectangle.CreateBoundingRectangle(MyRoute.Geometry);
                this.MyMap.SetView(locationRectangle, new Thickness(10));
            }
        }
Exemplo n.º 7
0
        void MyQuery_QueryCompleted(object sender, QueryCompletedEventArgs <Route> e)
        {
            if (e.Error == null)
            {
                Route    MyRoute    = e.Result;
                MapRoute MyMapRoute = new MapRoute(MyRoute);
                map_Fullscreen.AddRoute(MyMapRoute);

                List <string> RouteList = new List <string>();
                foreach (RouteLeg leg in MyRoute.Legs)
                {
                    foreach (RouteManeuver maneuver in leg.Maneuvers)
                    {
                        RouteList.Add(maneuver.InstructionText);
                    }
                }

                MyQuery.Dispose();
            }
        }
Exemplo n.º 8
0
        public async Task <Direction> WalkDistanceAsync(double sourceLat, double sourceLon, double targetLat, double targetLon)
        {
            Task     completeTask = new Task(() => { });
            double   length       = -1;
            TimeSpan time;

            var query = new RouteQuery
            {
                TravelMode = TravelMode.Walking,
                Waypoints  = new GeoCoordinate[] { new GeoCoordinate(sourceLat, sourceLon), new GeoCoordinate(targetLat, targetLon) }
            };

            query.QueryCompleted += delegate(object sender, QueryCompletedEventArgs <Microsoft.Phone.Maps.Services.Route> e)
            {
                if (e.Error == null)
                {
                    var resultRoute = e.Result;
                    length = resultRoute.LengthInMeters;
                    time   = resultRoute.EstimatedDuration;
                    //MapRoute MyMapRoute = new MapRoute(resultRoute);
                    query.Dispose();
                }
                completeTask.Start();
            };
            query.QueryAsync();

            await completeTask;

            if (length == -1)
            {
                return(null);
            }
            else
            {
                var res = new Direction {
                    DistanceInMeters = length, EstimatedDuration = time
                };
                return(res);
            }
        }
Exemplo n.º 9
0
        private void QueryCompleted(object sender, QueryCompletedEventArgs <Route> e)
        {
            if (e.Error == null)
            {
                try
                {
                    Route MyRoute = e.Result;
                    MyMapRoute       = new MapRoute(MyRoute);
                    MyMapRoute.Color = CurrentColor;
                    MyMap.AddRoute(MyMapRoute);
                    Route.Text = "";

                    List <string> RouteList = new List <string>();
                    foreach (RouteLeg leg in MyRoute.Legs)
                    {
                        foreach (RouteManeuver maneuver in leg.Maneuvers)
                        {
                            RouteList.Add(maneuver.InstructionText);
                        }
                    }

                    foreach (string line in RouteList)
                    {
                        Route.Text += dot + ". " + line + '\n';
                        dot++;
                    }

                    calculate.Text    = "Find cycle";
                    calculate.IconUri = new Uri("/Images/dark.shuffle.png", UriKind.Relative);
                    start.Text        = "Find path";
                    start.IconUri     = new Uri("/Images/dark.map.treasure.png", UriKind.Relative);
                    EnableAppButtons(true);

                    MyQuery.Dispose();
                }
                catch (InvalidOperationException ex)
                {
                }
            }
        }
Exemplo n.º 10
0
        private void routeQuery_QueryCompleted(object sender, QueryCompletedEventArgs <Route> e)
        {
            if (e.Error == null)
            {
                route = e.Result;
                MapRoute mapRoute = new MapRoute(route);
                myMap.AddRoute(mapRoute);

                rotas = new List <string>();

                foreach (RouteLeg leg in route.Legs)
                {
                    for (int idx = 1; idx < leg.Maneuvers.Count; idx++)
                    {
                        RouteManeuver maneuver = leg.Maneuvers[idx];
                        string        instructionText;

                        if (idx < (leg.Maneuvers.Count - 1))
                        {
                            instructionText = idx + ". " + maneuver.InstructionText;
                        }
                        else
                        {
                            instructionText = "»  " + maneuver.InstructionText;
                        }

                        rotas.Add(instructionText);
                    }
                }

                DrawMarkers();

                listaRotas.ItemsSource = rotas;

                FinalizaDisplay();

                routeQuery.Dispose();
                GC.SuppressFinalize(routeQuery);
            }
        }
Exemplo n.º 11
0
        /// <summary>
        /// Route Query completed event
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        ///

        void myRouteQuery_QueryCompleted(object sender, QueryCompletedEventArgs <Route> e)
        {
            try
            {
                if (e.Error == null && e.Result != null)
                {
                    Route    MyRoute    = e.Result;
                    MapRoute MyMapRoute = new MapRoute(MyRoute);
                    MyMapRoute.Color = (Colors.Blue);
                    myMap.AddRoute(MyMapRoute);
                    #region Draw source location ellipse
                    Ellipse myCircle = new Ellipse();
                    myCircle.Fill    = new SolidColorBrush(Colors.Blue);
                    myCircle.Height  = 20;
                    myCircle.Width   = 20;
                    myCircle.Opacity = 50;
                    MapOverlay myLocationOverlay = new MapOverlay();
                    myLocationOverlay.Content        = myCircle;
                    myLocationOverlay.PositionOrigin = new Point(0.5, 0.5);
                    myLocationOverlay.GeoCoordinate  = myRouteCoordinates[0];
                    MapLayer MylocationLayer = new MapLayer();
                    MylocationLayer.Add(myLocationOverlay);
                    myMap.Layers.Add(MylocationLayer);
                    #endregion
                    #region Draw target location ellipse
                    Ellipse CarCircle = new Ellipse();
                    CarCircle.Fill    = new SolidColorBrush(Colors.Red);
                    CarCircle.Height  = 20;
                    CarCircle.Width   = 20;
                    CarCircle.Opacity = 50;
                    MapOverlay CarLocationOverlay = new MapOverlay();
                    CarLocationOverlay.Content        = CarCircle;
                    CarLocationOverlay.PositionOrigin = new Point(0.5, 0.5);
                    CarLocationOverlay.GeoCoordinate  = myRouteCoordinates[1];
                    MapLayer CarlocationLayer = new MapLayer();
                    CarlocationLayer.Add(CarLocationOverlay);
                    myMap.Layers.Add(CarlocationLayer);
                    #endregion

                    double distanceInKm = (double)MyRoute.LengthInMeters / 1000;
                    textBoxDirections.Text = "Distance: " + distanceInKm.ToString("0.0") + " km, Time:"
                                             + MyRoute.EstimatedDuration.Hours + " hrs "
                                             + MyRoute.EstimatedDuration.Minutes + " mins." + Environment.NewLine;
                    List <string> routeInstructions = new List <string>();
                    foreach (RouteLeg leg in MyRoute.Legs)
                    {
                        for (int i = 0; i < leg.Maneuvers.Count; i++)
                        {
                            RouteManeuver maneuver        = leg.Maneuvers[i];
                            string        instructionText = maneuver.InstructionText;
                            distanceInKm = 0;

                            if (i > 0)
                            {
                                distanceInKm     = (double)leg.Maneuvers[i - 1].LengthInMeters / 1000;
                                instructionText += " (" + distanceInKm.ToString("0.0") + " km)";
                            }
                            routeInstructions.Add(instructionText);
                        }
                    }
                    foreach (string str in routeInstructions)
                    {
                        textBoxDirections.Text += str + Environment.NewLine;
                    }

                    myRouteQuery.Dispose();
                    progress.Visibility = Visibility.Collapsed;
                }
                else
                {
                    MessageBox.Show("Unable to generate route.");
                    progress.Visibility = Visibility.Collapsed;
                }
            }
            catch (Exception)
            {
                MessageBox.Show("Unable to generate route.");
                progress.Visibility = Visibility.Collapsed;
            }
        }
Exemplo n.º 12
0
//------------------------------ 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);
        }
Exemplo n.º 13
0
        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);
        }
Exemplo n.º 14
0
        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();
    }