PointLatLng end;   //终点
        private void AddMarkerCommandFunc(object obj)
        {
            start = new PointLatLng(36.7564903295052, 119.20166015625);
            end   = new PointLatLng(34.6332079113796, 114.873046875);

            RoutingProvider rp = MyMapControl.MainMap.MapProvider as RoutingProvider;

            if (rp == null)
            {
                rp = GMapProviders.BingHybridMap; // use OpenStreetMap if provider does not implement routing
            }

            MapRoute route = rp.GetRoute(start, end, false, false, (int)MyMapControl.MainMap.Zoom);

            if (route != null)
            {
                GMapMarker m1 = new GMapMarker(start);
                m1.Shape = new MyMarkerRouteAnchor(MyMapControl, m1, "Start: " + route.Name);

                GMapMarker m2 = new GMapMarker(end);
                m2.Shape = new MyMarkerRouteAnchor(MyMapControl, m2, "End: " + start.ToString());

                GMapRoute mRoute = new GMapRoute(route.Points);
                {
                    mRoute.ZIndex = -1;
                }

                MyMapControl.MainMap.Markers.Add(m1);
                MyMapControl.MainMap.Markers.Add(m2);
                MyMapControl.MainMap.Markers.Add(mRoute);

                MyMapControl.MainMap.ZoomAndCenterMarkers(null);
            }
        }
Example #2
0
        private void DrawRoute(MapRoute route)
        {
            var previousRoutes = MyMap.MapElements.Where(p => p.ZIndex == 2);

            if (previousRoutes.Any())
            {
                MyMap.MapElements.Remove(previousRoutes.First());
            }

            //Draw a semi transparent fat green line
            var color = Colors.Green;

            color.A = 128;
            var line = new MapPolyline
            {
                StrokeThickness = 11,
                StrokeColor     = color,
                StrokeDashed    = false,
                ZIndex          = 2
            };

            // Route has a Path containing all points to draw the route
            line.Path = new Geopath(route.Path.Positions);
            MyMap.MapElements.Add(line);
        }
Example #3
0
        public MapRoute GetRoute(PointLatLng start, PointLatLng end, bool avoidHighways, bool walkingMode, int Zoom)
        {
            List <PointLatLng> points = GetRoutePoints(MakeRoutingUrl(start, end, walkingMode ? TravelTypeFoot : TravelTypeMotorCar));
            MapRoute           route  = points != null ? new MapRoute(points, walkingMode ? WalkingStr : DrivingStr) : null;

            return(route);
        }
Example #4
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.");
            }
        }
Example #5
0
        private void btnAutoRoute_Click(object sender, EventArgs e)
        {
/*
 *          PointLatLng start = new PointLatLng(-25.974134, 32.593042);
 *          PointLatLng end = new PointLatLng(-25.959048, 32.592827);
 *          MapRoute route = GMap.NET.MapProviders.GoogleMapProvider.Instance.GetRoute(
 *            start, end, false, false, 15);
 *          gmap.Position = new PointLatLng(25.974134, -32.593042);
 *
 */
            //string start = "Avenida Armando Tivane, Maputo, Mozambique";
            //string end = "Rua 1301, Maputo, Mozambique";

            PointLatLng start = new PointLatLng(-25.974134, 32.593042);
            PointLatLng end   = new PointLatLng(-25.959048, 32.592827);
            MapRoute    route = GMap.NET.MapProviders.GoogleMapProvider.Instance.GetRoute(start, end, false, false, 10);


            GMapRoute r = new GMapRoute(route.Points, "My route");

            GMapOverlay routesOverlay = new GMapOverlay("routes");

            routesOverlay.Routes.Add(r);
            gmap.Overlays.Add(routesOverlay);
        }
        private void Button_Click(object sender, RoutedEventArgs e)
        {
            if (markerFrom != null && markerTo != null)
            {
                try
                {
                    RoutingProvider routingProvider =
                        mapView.MapProvider as RoutingProvider ?? GMapProviders.OpenStreetMap;

                    MapRoute route = routingProvider.GetRoute(
                        new PointLatLng(markerFrom.LocalPositionX, markerFrom.LocalPositionY), //start
                        new PointLatLng(markerTo.LocalPositionX, markerTo.LocalPositionY),     //end
                        true,                                                                  //avoid highways
                        true,                                                                  //walking mode
                        (int)mapView.Zoom);

                    GMapRoute gmRoute = new GMapRoute(route.Points);

                    mapView.Markers.Add(gmRoute);
                }catch (Exception ex)
                {
                    MessageBox.Show(ex.Message);
                }
            }
        }
Example #7
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();
     }
 }
        public MapRoute GetRoute(PointLatLng start, PointLatLng end, bool avoidHighways, bool walkingMode, int zoom)
        {
            MapRoute route = null;
            var      from  = new LatLng(start.Lat, start.Lng);
            var      to    = new LatLng(end.Lat, end.Lng);

            var direcrtionsRequest = new DirectionRequest()
            {
                Origin      = from,
                Destination = to,
                Sensor      = false,
                Mode        = walkingMode ? TravelMode.walking : TravelMode.driving
            };

            var directionService   = new DirectionService();
            var directionsResponse = directionService.GetResponse(direcrtionsRequest);

            if (directionsResponse.Status == ServiceResponseStatus.Ok)
            {
                if (directionsResponse.Routes.Any())
                {
                    var directionsRoute = directionsResponse.Routes[0];
                    // TODO
                    var pathPoints = AssembleHQPolyline(directionsRoute);

                    var pnts = (from p in pathPoints
                                select new PointLatLng(p.Latitude, p.Longitude)).ToList();

                    route = new MapRoute(pnts,
                                         directionsRoute.Summary);
                }
            }

            return(route);
        }
Example #9
0
        // adds route
        private void button12_Click(object sender, RoutedEventArgs e)
        {
            RoutingProvider rp = MainMap.MapProvider as RoutingProvider;

            if (rp == null)
            {
                rp = GMapProviders.OpenStreetMap; // use OpenStreetMap if provider does not implement routing
            }

            MapRoute route = rp.GetRoute(start, end, false, false, (int)MainMap.Zoom);

            if (route != null)
            {
                GMapMarker m1 = new GMapMarker(start);
                m1.Shape = new CustomMarkerDemo(this, m1, "Start: " + route.Name);

                GMapMarker m2 = new GMapMarker(end);
                m2.Shape = new CustomMarkerDemo(this, m2, "End: " + start.ToString());

                GMapRoute mRoute = new GMapRoute(route.Points);
                {
                    mRoute.ZIndex = -1;
                }

                MainMap.Markers.Add(m1);
                MainMap.Markers.Add(m2);
                MainMap.Markers.Add(mRoute);

                MainMap.ZoomAndCenterMarkers(null);
            }
        }
Example #10
0
    protected void Page_Load(object sender, EventArgs e)
    {
        try
        {
            if (!string.IsNullOrEmpty(Request["u"]) && !string.IsNullOrEmpty(Request["json"]))
            {
                string jsonString = Request["json"];

                Affine.Data.json.MapRoute mapRoute = serializer.Deserialize <Affine.Data.json.MapRoute>(jsonString);

                long userKey = Convert.ToInt64(Request["u"]);
                Affine.Data.MapRoute route = new MapRoute()
                {
                    Name          = mapRoute.Name,
                    City          = mapRoute.City,
                    Region        = mapRoute.Region,
                    Rating        = mapRoute.Rating,
                    PortalKey     = 0,              // TODO: send this in
                    UserKey       = userKey,
                    RouteDistance = mapRoute.RouteDistance,
                    LatMax        = mapRoute.LatMax,
                    LatMin        = mapRoute.LatMin,
                    LngMax        = mapRoute.LngMax,
                    LngMin        = mapRoute.LngMin,
                    CreationDate  = DateTime.Now
                };
                Affine.Data.MapRoutePoint[] points = mapRoute.MapRoutePoints.Select(mp => new Affine.Data.MapRoutePoint()
                {
                    Lat = mp.Lat, Lng = mp.Lng, Order = mp.Order, MapRoute = route
                }).ToArray <Affine.Data.MapRoutePoint>();
                route.MapRoutePoints.Concat(points);
                aqufitEntities entities = new aqufitEntities();
                entities.AddToMapRoutes(route);
                long     id                  = entities.SaveChanges();
                MapRoute passback            = entities.MapRoutes.Where(m => m.UserKey == userKey).OrderByDescending(m => m.Id).FirstOrDefault();
                Affine.Data.json.MapRoute mr = new Affine.Data.json.MapRoute()
                {
                    Id = passback.Id, Name = passback.Name, RouteDistance = passback.RouteDistance
                };
                string json = serializer.Serialize(mr);
                Response.Write(json);
            }
            else
            {
                Affine.Data.json.MapRoute route = new Affine.Data.json.MapRoute()
                {
                    Id = -1
                };
                Response.Write(serializer.Serialize(route));
            }
        }
        catch (Exception)
        {
            Affine.Data.json.MapRoute route = new Affine.Data.json.MapRoute()
            {
                Id = -1
            };
            Response.Write(serializer.Serialize(route));
        }
    }
Example #11
0
        public object Convert(object[] values, Type targetType, object parameter, CultureInfo culture)
        {
            GMapControl map = parameter as GMapControl;
            //double X1 = System.Convert.ToDouble(values[0]);
            //double Y1 = System.Convert.ToDouble(values[1]);
            //double X2 = System.Convert.ToDouble(values[2]);
            //double Y2 = System.Convert.ToDouble(values[3]);
            double d = (values[4] as CheckpointData).distance;
            //PointLatLng pos1 = map.FromLocalToLatLng((int)X1, (int)Y1);
            //PointLatLng pos2 = map.FromLocalToLatLng((int)X2, (int)Y2);
            //double R = 6378.1;
            //double track = Math.Atan2(Math.Cos(pos2.Lat * Math.PI / 180) * Math.Sin((pos2.Lng - pos1.Lng) * Math.PI / 180), Math.Cos(pos1.Lat * Math.PI / 180) * Math.Sin(pos2.Lat * Math.PI / 180) - Math.Sin(pos1.Lat * Math.PI / 180) * Math.Cos(pos2.Lat * Math.PI / 180) * Math.Cos((pos2.Lng - pos1.Lng) * Math.PI / 180));
            //double lat2 = Math.Asin(Math.Sin(pos1.Lat * Math.PI / 180) * Math.Cos(d / R) + Math.Cos(pos1.Lat * Math.PI / 180) * Math.Sin(d / R) * Math.Cos(track)) * 180 / Math.PI;
            //double lng2 = pos1.Lng + Math.Atan2(Math.Sin(track) * Math.Sin(d / R) * Math.Cos(pos1.Lat * Math.PI / 180), Math.Cos(d / R) - (Math.Sin(pos1.Lat * Math.PI / 180) * Math.Sin(lat2 * Math.PI / 180))) * 180 / Math.PI;
            //GPoint temp = map.FromLatLngToLocal(new PointLatLng(lat2, lng2));
            //Point local1 = new Point(X1, Y1);
            //Point local2 = new Point((int)temp.X, (int)temp.Y);
            //return Math.Sqrt(Math.Pow(local2.X - local1.X, 2) + Math.Pow(local2.Y - local1.Y, 2));
            PointLatLng pnt1 = map.FromLocalToLatLng(0, 20);
            PointLatLng pnt2 = map.FromLocalToLatLng(200, 20);
            double      dist = new MapRoute(new List <PointLatLng>()
            {
                pnt1, pnt2
            }, "B").Distance;
            double factor = 200 / dist;

            return(d * factor);
        }
        async Task DelayTime(PointLatLng _start, PointLatLng _end)
        {
            await Task.Delay(TimeSpan.FromSeconds(5));

            RoutingProvider rp = MyMapControl.MainMap.MapProvider as RoutingProvider;

            if (rp == null)
            {
                rp = GMapProviders.BingHybridMap; // use OpenStreetMap if provider does not implement routing
            }

            MapRoute route = rp.GetRoute(_start, _end, false, false, (int)MyMapControl.MainMap.Zoom);

            if (route != null)
            {
                GMapMarker m2 = new GMapMarker(_end);
                m2.Shape = new MyMarkerRouteAnchor(MyMapControl, m2, "End: " + start.ToString());

                GMapRoute mRoute = new GMapRoute(route.Points);
                {
                    mRoute.ZIndex = -1;
                }

                MyMapControl.MainMap.Markers.Add(m2);
                MyMapControl.MainMap.Markers.Add(mRoute);

                MyMapControl.MainMap.ZoomAndCenterMarkers(null);
            }
        }
Example #13
0
        //taxi
        private void Bcallcar_Click(object sender, RoutedEventArgs e)
        {
            endPoint = pointsofarea.Last();

            if (pointsofarea.Count != 0)
            {
                progressLine.Value = 0;
                foreach (MapObjectBase obj in mapObjects)
                {
                    if (obj is Human)
                    {
                        startPoint = (obj.getFocus());
                    }
                }

                Car   taxi = null;
                Human pl   = null;

                foreach (MapObjectBase obj in mapObjects)
                {
                    if (obj is Human)
                    {
                        pl = (Human)obj;
                        pl.destinationPoint = pointsofarea.Last();
                        break;
                    }
                }

                foreach (MapObjectBase obj in mapObjects)
                {
                    if (obj is Car)
                    {
                        taxi = (Car)obj;
                        break;
                    }
                }

                var t = taxi.moveTo(startPoint);
                addMarker(4, t.Points);

                // провайдер навигации
                RoutingProvider routingProvider = GMapProviders.OpenStreetMap;
                // определение маршрута
                MapRoute route = routingProvider.GetRoute(
                    startPoint, // начальная точка маршрута
                    endPoint,   // конечная точка маршрута
                    false,      // поиск по шоссе (false - включен)
                    false,      // режим пешехода (false - выключен)
                    15);
                addMarker(4, route.Points);
                taxi.Arrived += pl.CarArrived;
                pl.seated    += taxi.inTocar;
                taxi.Follow  += Focus_Follow;
            }
            else
            {
                MessageBox.Show("select an endpoint");
            }
        }
 public void AddRoute(MapRoute route, Color c)
 {
     if (route == null)
     {
         return;
     }
     AddRoute(route.Points, c);
 }
Example #15
0
        public MapRoute GetRoute(PointLatLng start, PointLatLng end, bool avoidHighways, bool walkingMode, int Zoom)
        {
            string             url    = MakeRouteUrl(start, end);
            string             result = HttpUtil.GetData(url);
            List <PointLatLng> points = new List <PointLatLng>();
            MapRoute           route  = points != null ? new MapRoute(points, "") : null;

            return(route);
        }
Example #16
0
        public static double GetDistanceByRoute(double startLat, double startLng, double endLat, double endLng)
        {
            GoogleMapProvider.Instance.ApiKey = "Your API Key";
            PointLatLng start = new PointLatLng(startLat, startLng);
            PointLatLng end   = new PointLatLng(endLat, endLng);
            MapRoute    route = GMap.NET.MapProviders.GoogleMapProvider.Instance.GetRoute(start, end, false, false, 15);

            return(route.Distance);
        }
Example #17
0
        /// <summary>
        /// It will first clear all the markers and the circle from the map.
        /// After that it will generate a route from your current position to your chosen destination.
        /// </summary>
        /// <param name="item">The marker on which you click as user</param>
        /// <param name="e"></param>
        private void CreateRoute(GMapMarker item, MouseEventArgs e)
        {
            _routes.Clear();
            _gMap.OnMarkerClick -= CreateRoute;
            MapRoute route = OpenStreetMapProvider.Instance.GetRoute(_currentPosition, item.Position, false, false, 15);

            _routes.Markers.Add(new GMarkerGoogle(item.Position, GMarkerGoogleType.blue));
            _routes.Routes.Add(new GMapRoute(route.Points, "Route"));
        }
Example #18
0
        private void stuvk_Click(object sender, RoutedEventArgs e)
        {
            {
                waybar.Value = 0;
                foreach (MapObject obj in mapObjects)
                {
                    if (obj is Human)
                    {
                        startOfRoute = (obj.getFocus());
                    }
                }
                endOfRoute = areapoints.Last();
                var besidedObj = mapObjects.OrderBy(mapObject => mapObject.getDistance(startOfRoute));

                Car   nearestCar = null;
                Human h          = null;

                foreach (MapObject obj in mapObjects)
                {
                    if (obj is Human)
                    {
                        h = (Human)obj;
                        h.destinationPoint = endOfRoute;
                        break;
                    }
                }

                foreach (MapObject obj in besidedObj)
                {
                    if (obj is Car)
                    {
                        nearestCar = (Car)obj;
                        break;
                    }
                }

                var aaa = nearestCar.MoveTo(startOfRoute);
                createMarker(aaa.Points, 3);

                RoutingProvider routingProvider = GMapProviders.OpenStreetMap;
                MapRoute        route           = routingProvider.GetRoute(
                    startOfRoute,
                    endOfRoute,
                    false,
                    false,
                    15);
                createMarker(route.Points, 3);
                nearestCar.Arrived += h.CarArrived;
                h.seated           += nearestCar.getintocar;
                nearestCar.Follow  += Focus_Follow;


                //  nearestCar.Arrived -= h.CarArrived;
                //  h.seated -= nearestCar.getintocar;
            }
        }
Example #19
0
 private void DrawRoute(List<Station> stations)
 {
     // Remove current route.
     if (_mapRoute != null)
     {
         _mapRoute.Remove();
     }
     // Create new route and add it to map.
     _mapRoute = new MapRoute(_map, stations);
 }
Example #20
0
 private void DrawRoute(ServerResponse serverResponse)
 {
     // Remove current route.
     if (_mapRoute != null)
     {
         _mapRoute.Remove();
     }
     // Create new route and add it to map.
     _mapRoute = new MapRoute(_map, serverResponse.response);
 }
Example #21
0
        public static GeoRoute BingMapToGeoRoute(this MapRoute route)
        {
            GeoRoute georoute = new GeoRoute();

            foreach (PointInt pos in route)
            {
                georoute.Add(BingMapTileSystem.PixelXYToLatLong(pos, route.Level));
            }
            return(georoute);
        }
Example #22
0
        public static MapRoute ToBingMapRoute(this GeoRoute route, int level)
        {
            MapRoute maproute = new MapRoute(level);

            foreach (PointLatLng pos in route)
            {
                maproute.Add(BingMapTileSystem.LatLngToPixelXY(pos, level));
            }
            return(maproute);
        }
Example #23
0
        public MapRoute MoveTo(PointLatLng endpoint)
        {
            RoutingProvider routingProvider = GMapProviders.OpenStreetMap;

            route = routingProvider.GetRoute(point, endpoint, false, false, 15);
            Thread ridingCar = new Thread(MoveByRoute);

            ridingCar.Start();
            return(route);
        }
        public static GeoRoute SingleMapToGeoRoute(this MapRoute route)
        {
            GeoRoute georoute = new GeoRoute();

            foreach (PointInt pos in route)
            {
                georoute.Add(SingleMapTransformSystem.PixelXYToModelXY(pos));
            }
            return(georoute);
        }
        public static MapRoute ToSingleMapRoute(this GeoRoute route)
        {
            MapRoute maproute = new MapRoute(0);

            foreach (PointLatLng pos in route)
            {
                maproute.Add(SingleMapTransformSystem.ModelXYToPixelXY(pos));
            }
            return(maproute);
        }
Example #26
0
    private void OnRemoveRoute(string name, MapLayer layer, MapRoute route)
    {
        Transform tran = this.m_grid.Find(name);

        if (tran == null)
        {
            return;
        }
        GameObject.DestroyImmediate(tran.gameObject);
    }
Example #27
0
        public virtual MapRoute GetRoute(PointLatLng start, PointLatLng end, bool avoidHighways, bool walkingMode, int Zoom, bool getInstructions = false)
        {
            var url = MakeRoutingUrl(start, end, walkingMode ? TravelTypeFoot : TravelTypeMotorCar, getInstructions);

            string routeXml = GMaps.Instance.UseRouteCache ? Cache.Instance.GetContent(url, CacheType.RouteCache) : string.Empty;

            if (string.IsNullOrEmpty(routeXml))
            {
                routeXml = GetContentUsingHttp(url);
                if (!string.IsNullOrEmpty(routeXml))
                {
                    if (GMaps.Instance.UseRouteCache)
                    {
                        Cache.Instance.SaveContent(url, CacheType.RouteCache, routeXml);
                    }
                }
            }

            MapRoute route = null;

            try
            {
                if (!string.IsNullOrEmpty(routeXml))
                {
                    XmlDocument xmldoc = new XmlDocument();
                    xmldoc.LoadXml(routeXml);
                    XmlNamespaceManager xmlnsManager = new XmlNamespaceManager(xmldoc.NameTable);
                    xmlnsManager.AddNamespace("sm", "http://earth.google.com/kml/2.0");

                    if (!string.IsNullOrEmpty(routeXml))
                    {
                        var points = GetRoutePoints(xmldoc, xmlnsManager);

                        if (points != null)
                        {
                            route = new MapRoute(points, walkingMode ? WalkingStr : DrivingStr)
                            {
                                TravelTime = GetTravelTime(xmldoc, xmlnsManager)
                            };

                            if (getInstructions)
                            {
                                route.Instructions.AddRange(GetInstructions(xmldoc, xmlnsManager));
                            }
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                Debug.WriteLine("GetRoute: " + ex);
            }

            return(route);
        }
Example #28
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();
     }
 }
Example #29
0
 private void GraphGenerator() // gerar matriz de custo
 {
     Graph = new double[pointLatLngs.Count, pointLatLngs.Count];
     for (int i = 0; i < Graph.GetLength(0); i++)
     {
         for (int j = 0; j < Graph.GetLength(1); j++)
         {
             MapRoute mapRoute = GoogleMapProvider.Instance.GetRoute(pointLatLngs[i], pointLatLngs[j], false, false, 12);
             Graph[i, j] = mapRoute.Distance;/// gera a matriz com valores
         }
     }
 }
Example #30
0
        private void timer1_Tick(object sender, EventArgs e)
        {
            GMap.NET.WindowsForms.Markers.GMarkerGoogle curPos = new GMap.NET.WindowsForms.Markers.GMarkerGoogle(initialPoint, GMap.NET.WindowsForms.Markers.GMarkerGoogleType.blue_pushpin);
            path = GMap.NET.MapProviders.GoogleMapProvider.Instance.GetRoute(initialPoint, finalPoint, false, false, 15);
            GMapRoute route = new GMapRoute(path.Points, "My route");

            overlayRoute.Routes.Clear();
            overlayRoute.Routes.Add(route);
            areaMap.Overlays.Add(overlayRoute);
            label10.Text = (path.Distance * 1000).ToString();
            areaMap.Refresh();
        }
Example #31
0
        private void button1_MouseClick(object sender, MouseEventArgs e)
        {
            PointLatLng end           = new PointLatLng(37.4340760558763, 55.7382816934103);
            PointLatLng start         = new PointLatLng(55.7390378802488, 37.4324790462873);
            MapRoute    route         = GoogleMapProvider.Instance.GetRoute(start, end, false, false, 14);
            GMapRoute   road          = new GMapRoute(route.Points, "My path");
            GMapOverlay routesOverlay = new GMapOverlay("path");

            routesOverlay.Routes.Add(road);
            gMapControl1.Overlays.Add(routesOverlay);
            //    //}
        }
Example #32
0
            public GMapRoute RoutAdd(RoutingProvider rp)
            {
                List <PointLatLng> ps = new List <PointLatLng>();

                for (int i = 0; i < Lpll.Count - 1; i++)
                {
                    MapRoute r = rp.GetRoute(Lpll[i], Lpll[i + 1], false, true, 13);
                    ps.AddRange(r.Points);
                }
                gMapRoute = new GMapRoute(ps);
                return(gMapRoute);
            }
Example #33
0
        public virtual void CalculateDistance()
        {
            if (TrackPoints.Count == 0)
            {
                Distance = null;
                return;
            }

            var points = TrackPoints.Select(p => new PointLatLng(p.Latitude, p.Longitude));

            Distance = new MapRoute(points, "").Distance;
        }
Example #34
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();
            }
        }
Example #35
0
    protected void Page_Load(object sender, EventArgs e)
    {
        try
        {
            if (!string.IsNullOrEmpty(Request["u"]) && !string.IsNullOrEmpty(Request["json"]))
            {
                string jsonString = Request["json"];

                Affine.Data.json.MapRoute mapRoute = serializer.Deserialize<Affine.Data.json.MapRoute>(jsonString);

                long userKey = Convert.ToInt64(Request["u"]);
                Affine.Data.MapRoute route = new MapRoute()
                {
                    Name = mapRoute.Name,
                    City = mapRoute.City,
                    Region = mapRoute.Region,
                    Rating = mapRoute.Rating,
                    PortalKey = 0,                  // TODO: send this in
                    UserKey = userKey,
                    RouteDistance = mapRoute.RouteDistance,
                    LatMax = mapRoute.LatMax,
                    LatMin = mapRoute.LatMin,
                    LngMax = mapRoute.LngMax,
                    LngMin = mapRoute.LngMin,
                    CreationDate = DateTime.Now
                };
                Affine.Data.MapRoutePoint[] points = mapRoute.MapRoutePoints.Select(mp => new Affine.Data.MapRoutePoint() { Lat = mp.Lat, Lng = mp.Lng, Order = mp.Order, MapRoute = route }).ToArray<Affine.Data.MapRoutePoint>();
                route.MapRoutePoints.Concat(points);
                aqufitEntities entities = new aqufitEntities();
                entities.AddToMapRoutes(route);
                long id = entities.SaveChanges();
                MapRoute passback = entities.MapRoutes.Where(m => m.UserKey == userKey ).OrderByDescending( m => m.Id).FirstOrDefault();
                Affine.Data.json.MapRoute mr = new Affine.Data.json.MapRoute() { Id = passback.Id, Name = passback.Name, RouteDistance = passback.RouteDistance };
                string json = serializer.Serialize(mr);
                Response.Write(json);
            }
            else
            {
                Affine.Data.json.MapRoute route = new Affine.Data.json.MapRoute() { Id = -1 };
                Response.Write(serializer.Serialize(route));
            }
        }
        catch (Exception)
        {
            Affine.Data.json.MapRoute route = new Affine.Data.json.MapRoute() { Id = -1 };
            Response.Write(serializer.Serialize(route));
        }
    }
Example #36
0
        private void MyQuery_QueryCompleted(object sender, QueryCompletedEventArgs<Route> e)
        {
            if (e.Error == null)
            {
                Route MyRoute = e.Result;
                MapRoute MyMapRoute = new MapRoute(MyRoute);
                MyMap.AddRoute(MyMapRoute);

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

                RouteLLS.ItemsSource = RouteList;

                MyQuery.Dispose();
            }


        }
        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));
            }
        }
        void routeQuery_QueryCompleted(object sender, QueryCompletedEventArgs<Route> e)
        {

            if (e.Error == null)
            {
                Route MyRoute = e.Result;
                MapRoute MyMapRoute = new MapRoute(MyRoute);
                map.Center = MyCoordinates[0];
                map.AddRoute(MyMapRoute);
            }

            if (routeQuery != null)
                routeQuery.Dispose();

            if (MyCoordinates != null)
                MyCoordinates.Clear();

            pointCount = 0;
        }
 void routeQuery_QueryCompleted(object sender, QueryCompletedEventArgs<Route> e)
 {
     if (null == e.Error)
     {
         Route MyRoute = e.Result;
         MapRoute MyMapRoute = new MapRoute(MyRoute);
         MyMapControl.AddRoute(MyMapRoute);
         MyMapControl.SetView(MyMapRoute.Route.BoundingBox);
     }
     else
         MessageBox.Show("Error occured:\n" + e.Error.Message);
 }
Example #40
0
 void routeQuery_QueryCompleted(object sender, QueryCompletedEventArgs<Route> e)
 {
     if (e.Error == null)
     {
         Route route = e.Result;
         MapRoute mapRoute = new MapRoute(route);
         myMap.AddRoute(mapRoute);
         string routeContent = "";
         foreach (RouteLeg leg in route.Legs)
         {
             foreach (RouteManeuver routeManeuver in leg.Maneuvers)
             {
                 routeContent += routeManeuver.InstructionText;
                 Debug.WriteLine(routeManeuver.InstructionText);
             }
         }
         MessageBox.Show(routeContent);
     }
     else
     {
         MessageBox.Show("无法查到路线");
     }
 }
Example #41
0
 /// <summary>
 /// CÁI NÀY ĐỂ VẼ ĐƯỜNG ĐI GIỮA 2 điểm
 /// </summary>
 /// <param name="startPosition"></param>
 /// <param name="endPosition"></param>
 private void GetRouteOnMap(GeoCoordinate startPosition, GeoCoordinate endPosition)
 {
     if (driverMapRoute != null)
     {
         map_DriverMap.RemoveRoute(driverMapRoute);
         driverMapRoute = null;
         driverQuery = null;
         map_DriverMap.Layers.Remove(driverMapLayer);
     }
     driverQuery = new RouteQuery()
     {
         TravelMode = TravelMode.Driving,
         Waypoints = new List<GeoCoordinate>()
     {
         startPosition, 
         endPosition
     },
         RouteOptimization = RouteOptimization.MinimizeTime
     };
     driverQuery.QueryCompleted += driverRouteQuery_QueryCompleted;
     driverQuery.QueryAsync();
 }
Example #42
0
        void MyQueryPoiSearch_QueryCompleted(object sender, QueryCompletedEventArgs<Route> e)
        {
            if (e.Error == null)
            {
                var myRoute = e.Result;
                if (!_sourcePoi)
                {
                    _myMapRoute = new MapRoute(myRoute);
                    Mymap.AddRoute(_myMapRoute);
                    // time to destination
                    var time1 = myRoute.EstimatedDuration;
                    time.Text = "Duration: " + time1.ToString();

                    // total meters
                    Dispatcher.BeginInvoke(() =>
                    {
                        var meters = myRoute.LengthInMeters;
                        var kilometers = meters / 1000.0;
                        distance.Text = "Distance: " + kilometers.ToString(CultureInfo.InvariantCulture) + " Km";
                    });
                }
                else
                {
                    time.Text = "Duration: Unknown";
                    // total meters
                    Dispatcher.BeginInvoke(() =>
                    {
                        distance.Text = "Distance: Unknown";
                    });
                }


                routeNavDetails.Clear();
                var routeList = new List<DirectionsList>();
                if (!_sourcePoi)
                {
                    foreach (var leg in myRoute.Legs)
                    {
                        foreach (var maneuver in leg.Maneuvers)
                        {
                            var direction = new DirectionsList();
                            var det = new RouteDetails
                            {
                                instractions = maneuver.InstructionText,
                                coordinate =
                                    new GeoCoordinate(maneuver.StartGeoCoordinate.Latitude,
                                        maneuver.StartGeoCoordinate.Longitude),
                                distance = maneuver.LengthInMeters
                            };
                            routeNavDetails.Add(det);
                            var dist = maneuver.LengthInMeters / 1000.0;
                            var str = maneuver.InstructionText.ToUpper();
                            if (str.Contains("LEFT"))
                                direction.image = new BitmapImage(new Uri("/Assets/Navigation/turn-left.png", UriKind.Relative));
                            else if (str.Contains("RIGHT"))
                                direction.image = new BitmapImage(new Uri("/Assets/Navigation/turn-right.png", UriKind.Relative));
                            else if (str.Contains("HEAD"))
                                direction.image = new BitmapImage(new Uri("/Assets/start.png", UriKind.Relative));
                            else if (str.Contains("YOU HAVE"))
                                direction.image = new BitmapImage(new Uri("/Assets/finish.png", UriKind.Relative));
                            else if (str.Contains("TRAFFIC CIRCLE"))
                                direction.image = new BitmapImage(new Uri("/Assets/Navigation/trafficcircle.png", UriKind.Relative));
                            direction.distance = dist.ToString(CultureInfo.InvariantCulture) + " Km";
                            direction.direction = maneuver.InstructionText;
                            direction.geocoordinate = det.coordinate;
                            routeList.Add(direction);
                        }
                    }
                }
                if (_getIndoornav)
                {
                    if (Mymap.Layers.Contains(indoorLayer))
                    {
                        Mymap.Layers.Remove(indoorLayer);
                    }



                    if (_poisByBuilding != null)
                    {
                        foreach (var obj1 in _poisByBuilding.pois)
                        {
                            if (obj1.puid.Equals(_floorPoiFrom))
                            {
                                if (obj1.is_building_entrance.Equals("true"))
                                {
                                    var direction = new DirectionsList
                                    {
                                        direction = "Get into Building",
                                        geocoordinate =
                                            new GeoCoordinate(double.Parse(obj1.coordinates_lat, CultureInfo.InvariantCulture),
                                                double.Parse(obj1.coordinates_lon, CultureInfo.InvariantCulture)),
                                        image =
                                            new BitmapImage(new Uri("/Assets/Navigation/entrance.png", UriKind.Relative))
                                    };
                                    routeList.Add(direction);

                                    _overlayFrom = new MapOverlay();
                                    var im = new Image
                                    {
                                        Source =
                                            new BitmapImage(new Uri("/Assets/Navigation/entrance.png", UriKind.Relative)),
                                        Width = 64,
                                        Height = 64
                                    };
                                    _overlayFrom.Content = im;
                                    _overlayFrom.GeoCoordinate = direction.geocoordinate; ;
                                    _overlayFrom.PositionOrigin = new Point(0.5, 1.0);
                                }
                                else
                                {
                                    var direction = new DirectionsList
                                    {
                                        direction = obj1.name,
                                        geocoordinate =
                                            new GeoCoordinate(double.Parse(obj1.coordinates_lat, CultureInfo.InvariantCulture),
                                                double.Parse(obj1.coordinates_lon, CultureInfo.InvariantCulture)),
                                        image = new BitmapImage(new Uri("/Assets/start.png", UriKind.Relative))
                                    };
                                    routeList.Add(direction);

                                    _overlayFrom = new MapOverlay();
                                    var im = new Image
                                    {
                                        Source = new BitmapImage(new Uri("/Assets/start.png", UriKind.Relative)),
                                        Width = 64,
                                        Height = 64
                                    };
                                    _overlayFrom.Content = im;
                                    _overlayFrom.GeoCoordinate = direction.geocoordinate; ;
                                    _overlayFrom.PositionOrigin = new Point(0.0, 1.0);
                                }
                            }
                        }

                        Mymap.SetView(set_coordinates, 20, MapAnimationKind.Parabolic);
                    }

                    if (_poisByBuilding != null)
                    {
                        foreach (var obj1 in _poisByBuilding.pois)
                        {
                            if (obj1.puid.Equals(_floorPoiTo))
                            {
                                var direction = new DirectionsList
                                {
                                    direction = obj1.name,
                                    geocoordinate =
                                        new GeoCoordinate(double.Parse(obj1.coordinates_lat, CultureInfo.InvariantCulture),
                                            double.Parse(obj1.coordinates_lon, CultureInfo.InvariantCulture)),
                                    image = new BitmapImage(new Uri("/Assets/finish.png", UriKind.Relative))
                                };
                                routeList.Add(direction);

                                _overlayTo = new MapOverlay();
                                var im = new Image
                                {
                                    Source = new BitmapImage(new Uri("/Assets/finish.png", UriKind.Relative))
                                };
                                _overlayTo.Content = im;
                                _overlayTo.GeoCoordinate = direction.geocoordinate; ;
                                _overlayTo.PositionOrigin = new Point(1.0, 1.0);
                            }
                        }
                    }
                    indoorLayer.Clear();

                    if (Mymap.Layers.Contains(indoorLayer))
                        Mymap.Layers.Remove(indoorLayer);
                    if (_floorPoiFromNumber == _floorPoiToNumber)
                    {
                        if (_selectedFloor == _floorPoiToNumber)
                        {
                            indoorLayer.Add(_overlayFrom);
                            indoorLayer.Add(_overlayTo);
                        }
                    }
                    else
                    {
                        if (_selectedFloor == _floorPoiFromNumber)
                        {
                            indoorLayer.Add(_overlayFrom);
                        }
                        else
                            if (_selectedFloor == _floorPoiToNumber)
                                indoorLayer.Add(_overlayTo);
                    }
                    Mymap.Layers.Add(indoorLayer);
                }
                //_sourcePoi = false;
                CreaterouteOverlays();
                RouteLLS.ItemsSource = routeList;
                RouteLLS.SelectionChanged += RouteLLS_SelectionChanged;
                MyQuery.Dispose();
            }

            calcroutestext.Visibility = Visibility.Collapsed;
            calcProgrBar.Visibility = Visibility.Collapsed;
            time.Visibility = Visibility.Visible;
            distance.Visibility = Visibility.Visible;

        }
Example #43
0
        void MyQuery_QueryCompleted(object sender, QueryCompletedEventArgs<Route> e)
        {
            if (e.Error == null)
            {
                var myRoute = e.Result;
                _myMapRoute = new MapRoute(myRoute);
                Mymap.AddRoute(_myMapRoute);
                // time to destination
                var time1 = myRoute.EstimatedDuration;
                time.Text = "Duration: " + time1.ToString();

                // total meters
                Dispatcher.BeginInvoke(() =>
                {
                    var meters = myRoute.LengthInMeters;
                    var kilometers = meters / 1000.0;
                    distance.Text = "Distance: " + kilometers.ToString(CultureInfo.InvariantCulture) + " Km";
                });
                routeNavDetails.Clear();
                var routeList = new List<DirectionsList>();
                foreach (var leg in myRoute.Legs)
                {
                    foreach (var maneuver in leg.Maneuvers)
                    {
                        var direction = new DirectionsList();
                        var det = new RouteDetails
                        {
                            instractions = maneuver.InstructionText,
                            coordinate =
                                new GeoCoordinate(maneuver.StartGeoCoordinate.Latitude,
                                    maneuver.StartGeoCoordinate.Longitude),
                            distance = maneuver.LengthInMeters
                        };
                        routeNavDetails.Add(det);
                        var dist = maneuver.LengthInMeters / 1000.0;
                        var str = maneuver.InstructionText.ToUpper();
                        if (str.Contains("LEFT"))
                            direction.image =
                                new BitmapImage(new Uri("/Assets/Navigation/turn-left.png", UriKind.Relative));
                        else if (str.Contains("RIGHT"))
                            direction.image =
                                new BitmapImage(new Uri("/Assets/Navigation/turn-right.png", UriKind.Relative));
                        else if (str.Contains("HEAD"))
                            direction.image = new BitmapImage(new Uri("/Assets/start.png", UriKind.Relative));
                        else if (str.Contains("YOU HAVE"))
                            direction.image = new BitmapImage(new Uri("/Assets/finish.png", UriKind.Relative));
                        else if (str.Contains("TRAFFIC CIRCLE"))
                            direction.image =
                                new BitmapImage(new Uri("/Assets/Navigation/trafficcircle.png", UriKind.Relative));
                        direction.distance = dist.ToString(CultureInfo.InvariantCulture) + " Km";
                        direction.direction = maneuver.InstructionText;
                        direction.geocoordinate = det.coordinate;
                        routeList.Add(direction);
                    }
                }
                CreaterouteOverlays();
                RouteLLS.ItemsSource = routeList;
                RouteLLS.SelectionChanged += RouteLLS_SelectionChanged;
                MyQuery.Dispose();
            }
            else
            {
                ApplicationBar.IsVisible = true;
                MoveViewWindow(30);
                directions_grid.Visibility = Visibility.Collapsed;
                stackpanelClose();
                MessageBox.Show("Cannot get directions to the selected poi!");
            }

            calcroutestext.Visibility = Visibility.Collapsed;
            calcProgrBar.Visibility = Visibility.Collapsed;
            time.Visibility = Visibility.Visible;
            distance.Visibility = Visibility.Visible;

        }
Example #44
0
        void geoQ_QueryCompleted(object sender, QueryCompletedEventArgs<Route> e)
        {
            Debug.WriteLine("Route query, error: " + e.Error);
            Debug.WriteLine("Route query, cancelled: " + e.Cancelled);
            Debug.WriteLine("Route query, cancelled: " + e.UserState);
            /*
            if (LastRutte != null)
            {
                MapView.RemoveRoute(LastRutte);
                LastRutte = null;
            }
            */
            if (e.Error == null)
            {
                Route myRutte = e.Result;
                LastRutte = new MapRoute(myRutte);

                // myRutte.Legs.Count();

                MapView.AddRoute(LastRutte);
                MapView.SetView(e.Result.BoundingBox);
            }
        }
        void geoQ_QueryCompleted(object sender, QueryCompletedEventArgs<Route> e)
        {
            Debug.WriteLine("Route query, error: " + e.Error);
            Debug.WriteLine("Route query, cancelled: " + e.Cancelled);
            Debug.WriteLine("Route query, cancelled: " + e.UserState);

            if (LastRutte != null)
            {
                map1.RemoveRoute(LastRutte);
                LastRutte = null;
            }

            Route myRutte = e.Result;


            for (var i = 0; i < myRutte.Legs.Count(); i++)
            {
                // you could also access each leg separately, and add markers etc into the map for them.
            }
            LastRutte = new MapRoute(myRutte);

            map1.AddRoute(LastRutte);
            map1.SetView(e.Result.BoundingBox);

            MessageBox.Show("Distance: " + (myRutte.LengthInMeters / 1000) + " km, Estimated traveltime: " + myRutte.EstimatedDuration);
        }
Example #46
0
 void routeQuery_QueryCompleted(object sender, QueryCompletedEventArgs<Route> e)
 {
     try
     {
         mapRoute = new MapRoute(e.Result);
         mapRoute.Color = System.Windows.Media.Color.FromArgb(255, 187, 18, 161);
         mapJourney.AddRoute(mapRoute);
         query.QueryCompleted -= routeQuery_QueryCompleted;
     }
     catch { }           
 }
Example #47
0
        /// <summary>
        /// Event handler for route query completed.
        /// </summary>
        /// <param name="e">Results of the geocode query - the route</param>
        private void RouteQuery_QueryCompleted(object sender, QueryCompletedEventArgs<Route> e)
        {
            HideProgressIndicator();
            if (e.Error == null)
            {
                MyRoute = e.Result;
                MyMapRoute = new MapRoute(MyRoute);
                MyMap.AddRoute(MyMapRoute);

                // Update route information and directions
                DestinationText.Text = SearchTextBox.Text;
                double distanceInKm = (double)MyRoute.LengthInMeters / 1000;
                DestinationDetailsText.Text = distanceInKm.ToString("0.0") + " km, "
                                              + MyRoute.EstimatedDuration.Hours + " hrs "
                                              + MyRoute.EstimatedDuration.Minutes + " mins.";

                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);
                    }
                }
                RouteLLS.ItemsSource = routeInstructions;

                AppBarDirectionsMenuItem.IsEnabled = true;

                if (_isDirectionsShown)
                {
                    // Center map on the starting point (phone location) and zoom quite close
                    MyMap.SetView(MyCoordinate, 16, MapAnimationKind.Parabolic);
                }
                else
                {
                    // Center map and zoom so that whole route is visible
                    MyMap.SetView(MyRoute.Legs[0].BoundingBox, MapAnimationKind.Parabolic);
                }
                MyRouteQuery.Dispose();
            }
            DrawMapMarkers(false);
        }
Example #48
0
        void driverRouteQuery_QueryCompleted(object sender, QueryCompletedEventArgs<Route> e)
        {
            if (e.Error == null)
            {
                Route newRoute = e.Result;

                driverMapRoute = new MapRoute(newRoute);
                driverMapRoute.Color = Color.FromArgb(255, (byte)0, (byte)171, (byte)243); // aRGB for #00abf3
                driverMapRoute.OutlineColor = Color.FromArgb(255, (byte)45, (byte)119, (byte)191); //2d77bf
                map_DriverMap.AddRoute(driverMapRoute);
                //map_RiderMap.SetView(newRoute);                
                driverQuery.Dispose();

            }
        }
        /// <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.");
            }
        }
Example #50
0
        void driverTrackingRouteQuery_QueryCompleted(object sender, QueryCompletedEventArgs<Route> e)
        {
            if (e.Error == null)
            {
                Route newRoute = e.Result;

                driverMapTrackerRoute = new MapRoute(newRoute);
                driverMapTrackerRoute.Color = Color.FromArgb(255, (byte)220, (byte)29, (byte)81); // aRGB for #dc1d51           
                driverMapTrackerRoute.OutlineColor = Colors.Transparent;
                map_DriverMap.AddRoute(driverMapTrackerRoute);
                //map_RiderMap.SetView(newRoute);                
                driverMapTrackerQuery.Dispose();

            }
        }
        void MyQuery_QueryCompleted(object sender, QueryCompletedEventArgs<Route> e)
        {
            if (e.Error == null)
            {
                Route MyRoute = e.Result;
                MapRoute MyMapRoute = new MapRoute(MyRoute);
                XAMLMap.AddRoute(MyMapRoute);

                MyQuery.Dispose();
            }
        }
Example #52
0
 /// <summary>
 /// Cái này để xóa route
 /// </summary>
 private void RemoveMapRoute()
 {
     if (driverMapRoute != null)
     {
         map_DriverMap.RemoveRoute(driverMapRoute);
         driverMapLayer.Remove(driverDestinationIconOverlay);
         map_DriverMap.Layers.Remove(driverMapLayer);
         driverMapRoute = null;
         driverQuery = null;
         driverDestinationIconOverlay = null;
     }
 }
        private void GenerateNewRoute()
        {
            MapTile currentPosition = this.Ant.CurrentPosition;
            int counter = 0;

            do
            {
                for (int i = GameContext.ViewRadius - 1; i > ConsiderAlternativeWhenMovesLeft; i--)
                {
                    int radi = i;
                    MapTile destination = (from t in currentPosition.CircleFromCenter(radi)
                                           where this.IsInGeneralDirection(currentPosition, t, radi)
                                           select t).FirstOrDefault();

                    if (destination == null)
                        continue;

                    this._route = currentPosition
                        .ShortestRouteTo(destination, GameContext.ViewRadius*2)
                        .FirstOrDefault();
                }
            } while (this._route == null && (++counter < 6));

            this._stepsMade = 0;
        }
Example #54
0
 private void RemoveMapRouteOnly()
 {
     if (driverMapRoute != null)
     {
         map_DriverMap.RemoveRoute(driverMapRoute);
         driverMapRoute = null;
         driverQuery = null;
     }
 }
 public HeatMovementRequestEvent(MapRoute route)
 {
     this.Route = route;
 }
Example #56
0
 /// <summary>
 /// Cái này để xóa route
 /// </summary>
 private void RemoveTrakingMapRoute()
 {
     if (driverMapTrackerRoute != null)
     {
         map_DriverMap.RemoveRoute(driverMapTrackerRoute);
         driverMapTrackerRoute = null;
         driverMapTrackerQuery = null;
     }
 }
 public MapRoute GetRoute(string start, string end, bool avoidHighways, bool walkingMode, int Zoom)
 {
     string tooltip;
     int numLevels;
     int zoomFactor;
     MapRoute ret = null;
     List<PointLatLng> points = GetRoutePoints(MakeRouteUrl(start, end, LanguageStr, avoidHighways, walkingMode), Zoom, out tooltip, out numLevels, out zoomFactor);
     if (points != null)
     {
         ret = new MapRoute(points, tooltip);
     }
     return ret;
 }
Example #58
0
        /// <summary>
        /// Hàm này để đặt lại mọi trạng thái điều kiện
        /// </summary>
        private void ResetFlag()
        {
            //For Router        
            driverGeocodeQuery = null;
            driverQuery = null;
            driverMapRoute = null;
            driverRoute = null;

            //For get Current Location
            driverFirstGeolocator = null;
            driverFirstGeoposition = null;
            driverMapOverlay = null;
            driverMapLayer = null;

            //For Router        
            driverGeocodeQuery = null;
            driverQuery = null;
            driverMapRoute = null;
            driverRoute = null;

            //For get Current Location
            driverFirstGeolocator = null;
            driverFirstGeoposition = null;
            driverMapOverlay = null;
            driverMapLayer = null;

            //Rider Destination Icon Overlay
            driverDestinationIconOverlay = null;

            //For Update Current Location
            currentLat = 0;
            currentLng = 0;
            countForUpdateLocation = 0;

            //For trip
            newTrip = null;
            myTrip = null;

            //For Trip Complete
            startLatitude = 0;
            startLongitude = 0;
            endLatitude = 0;
            endLongitude = 0;
            isTrack = false;
            estimateCost = 0;
            totalFare = 0;

            //For Distance
            distanceKm = 0;

            //mySelectedVehicle = null;
            if (tNetTripData != null)
            {
                tNetTripData = null;
            }

            //for complete trip
            completeTrip = null;

            //For continous tracking on map
            fiveStepBeforeLat = 0;
            fiveStepBeforeLng = 0;
            fiveStepAfterLat = 0;
            fiveStepAfterLng = 0;
            //driverMapTrackerQuery = null;
            //driverMapTrackerRoute = null;
            isTrackingRoute = false;
            countTracking = 0;
            //driverMapTrakerLayer = null;
            //driverMapTrackerOverlay = null;

            isCalculateFare = false;

            realDistance = 0;
            realFare = 0;
            isFinishTrip = false;

            isTrakingStated = false;

            txt_DistanceKm.Text = "0.0 (km)";
            txt_PricePerDistance.Text = "0.000 (đ)";
            txt_TotalPrice.Text = "0.000 (đ)";            
        }
        protected void bAjaxPostback_Click(object sender, EventArgs e)
        {
            switch (hiddenAjaxAction.Value)
            {
                case "saveRoute":
                    aqufitEntities entities = new aqufitEntities();
                    Affine.Data.MapRoute route = new MapRoute()
                    {
                        Name = atiGMapRoute.RouteTitle,
                        PortalKey = this.PortalId,                  // TODO: send this in
                        UserSetting = entities.UserSettings.First( u => u.Id == UserSettings.Id ),
                        RouteDistance = atiGMapRoute.RouteDistance,
                        CreationDate = DateTime.Now,
                        WorkoutTypeId = atiGMapRoute.WorkoutTypeKey
                    };

                    entities.AddToMapRoutes(route);
                    double zoom = atiGMapRoute.FitZoom;
                    double w = atiGMapRoute.MapWidth/200.0;
                    double h = atiGMapRoute.MapHeight/100.0;
                    double r = w > h ? w : h;
                    zoom = r > 0 ? zoom - Math.Sqrt(r) : zoom + Math.Sqrt(r);
                    route.ThumbZoom = (short)Math.Floor(zoom);

                    Affine.Data.MapRoutePoint[] points = atiGMapRoute.MapRoutePoints.Select(mp => new Affine.Data.MapRoutePoint() { Lat = mp.Lat, Lng = mp.Lng, Order = mp.Order, MapRoute = route }).ToArray<Affine.Data.MapRoutePoint>();
                    route.MapRoutePoints.Concat(points);
                    double minLat = double.MaxValue;
                    double minLng = double.MaxValue;
                    double maxLat = double.MinValue;
                    double maxLng = double.MinValue;
                    foreach( Affine.Data.MapRoutePoint p in points )
                    {
                        if (p.Lat < minLat)
                        {
                            minLat = p.Lat;
                        }
                        if (p.Lng < minLng)
                        {
                            minLng = p.Lng;
                        }
                        if (p.Lat > maxLat)
                        {
                            maxLat = p.Lat;
                        }
                        if (p.Lng > maxLng)
                        {
                            maxLng = p.Lng;
                        }
                    }
                    route.LatMax = maxLat;
                    route.LatMin = minLat;
                    route.LngMax = maxLng;
                    route.LngMin = minLng;
                    // Cull points until there are 100 or less points to make the encoded polyline fit the 512 bytes
                    int len = 100;
                    IList<Affine.Data.MapRoutePoint> pointCopy = atiGMapRoute.MapRoutePoints.Select(mp => new Affine.Data.MapRoutePoint() { Lat = mp.Lat, Lng = mp.Lng, Order = mp.Order }).ToList<Affine.Data.MapRoutePoint>();
                    pointCopy = CullPoints(pointCopy, len);
                    route.PolyLineEncoding = Affine.Utils.PolylineEncoder.createEncodings(pointCopy, 17, 1)["encodedPoints"].ToString();
                    while (route.PolyLineEncoding.Length > 512)
                    {
                        len = len/2;
                        pointCopy = CullPoints(pointCopy, len);
                        route.PolyLineEncoding = Affine.Utils.PolylineEncoder.createEncodings(pointCopy, 17, 1)["encodedPoints"].ToString();
                    }
                    entities.SaveChanges();
                    MapRoute passback = entities.MapRoutes.Where(m => m.UserSetting.Id == this.UserSettings.Id && m.PortalKey == this.PortalId ).OrderByDescending( m => m.Id).FirstOrDefault();
                    // routes creater needs the route to show up in their route list now.
                    User2MapRouteFav fav = new User2MapRouteFav()
                    {
                        MapRoute = passback,
                        UserSettingsKey = UserSettings.Id
                    };
                    entities.AddToUser2MapRouteFav(fav);
                    entities.SaveChanges();

                    Affine.Data.json.MapRoute mr = new Affine.Data.json.MapRoute() { Id = passback.Id, Name = passback.Name, RouteDistance = passback.RouteDistance };
                    RadAjaxManager1.ResponseScripts.Add(" setSelectedMap(" + passback.Id + ", '" + passback.Name + "', " + passback.RouteDistance + ", ''); ");
                    break;
            }
            // save and close  RadAjaxManager1.ResponseScripts.Add();  /
        }
Example #60
0
        void WalkingRouteQuery_QueryCompleted(object sender, QueryCompletedEventArgs<Route> e)
        {
            progressBar.Visibility = Visibility.Collapsed;
            if (e.Result.Legs.Count() != 0)
            {
                
                Route MyRoute = e.Result;
                MyMapRoute = new MapRoute(MyRoute);
                MyMapRoute.Color = new SolidColorBrush((Color)Application.Current.Resources["PhoneAccentColor"]).Color;
                stopsMap.AddRoute(MyMapRoute);
                if (((ItemViewModel)(MainLongListSelector.SelectedItem)) == null)
                {
                    ((ItemViewModel)(MainLongListSelector.ItemsSource[0])).LineFive = GetWalkTime(e); ;

                }
                else
                {
                    ((ItemViewModel)(MainLongListSelector.ItemsSource[0])).LineFive = GetWalkTime(e);

                }

            }
            else
            {
                MessageBox.Show("No walking routes available for chosen location. Please choose again");
            }
        }