Пример #1
0
        public IEnumerable <NavigationRoute> TestDbConn()
        {
            IEnumerable <NavigationRoute> routes = Enumerable.Empty <NavigationRoute>();

            try
            {
                string connStr = _config.GetSection("Configuration").GetSection("ConnString").Value;
                using (SqlConnection conn = new SqlConnection(connStr))
                {
                    SqlCommand cmd = new SqlCommand();
                    conn.Open();
                }
            }
            catch (SystemException ex)
            {
                var route1 = new NavigationRoute
                {
                    Id       = 1,
                    Route    = "error",
                    Name     = "scheduler",
                    Icon     = "education",
                    ModuleId = "../scheduler/scheduler",
                    Nav      = true,
                    Title    = "Error"
                };

                routes = routes.Concat(new[] { route1 });

                return(routes);
            }

            return(routes);
        }
Пример #2
0
        private async void BuildingRouteAsync()
        {
            var             id      = Intent.GetStringExtra(IDPED);
            string          sql     = string.Format("Select * From TapFood.Pedido Where(IdPedido='{0}') Limit 1", id);
            MySqlCommand    command = new MySqlCommand(sql, conn);
            MySqlDataReader reader;

            reader = command.ExecuteReader();
            reader.Read();
            double latusr = (double)reader["LatitudUsuario"];
            double lngusr = (double)reader["LongitudUsuario"];
            double latrep = (double)reader["LatitudRepartidor"];
            double lngrep = (double)reader["LongitudRepartidor"];

            MapboxNavigation navigation = new MapboxNavigation(this, MAPBOX_KEY);

            Point origin      = Point.FromLngLat(lngusr, latusr);
            Point destination = Point.FromLngLat(lngrep, latrep);

            var response = await NavigationRoute
                           .GetBuilder()
                           .AccessToken(Mapbox.AccessToken)
                           .Origin(origin)
                           .Destination(destination)
                           .Build()
                           .GetRouteAsync();

            System.Diagnostics.Debug.WriteLine(response);
        }
Пример #3
0
        private void FetchRoute()
        {
            NavigationRoute.Builder builder = NavigationRoute.InvokeBuilder(this)
                                              .AccessToken(Mapbox.Mapboxsdk.Mapbox.AccessToken)
                                              .Origin(currentLocation)
                                              .Profile(GetRouteProfileFromSharedPreferences())
                                              .Alternatives((Java.Lang.Boolean)true);

            foreach (Point wayPoint in wayPoints)
            {
                builder.AddWaypoint(wayPoint);
            }

            SetFieldsFromSharedPreferences(builder);
            builder.Build().GetRoute(new MyGetRouteCallback((routes) =>
            {
                HideLoading();
                route = routes[0];
                if (Convert.ToInt32(route.Distance()) > 25)
                {
                    launchRouteBtn.Enabled = true;
                    map.DrawRoutes(routes);
                    BoundCameraToRoute();
                }
                else
                {
                    Snackbar.Make(mapView, Resource.String.error_select_longer_route, Snackbar.LengthShort).Show();
                }
            }));
            loading.Visibility = ViewStates.Visible;
        }
Пример #4
0
        async void CalculateRoute()
        {
            Location userLocation = mapboxMap.MyLocation;

            if (userLocation == null)
            {
                System.Diagnostics.Debug.WriteLine("calculateRoute: User location is null, therefore, origin can't be set.");
                return;
            }

            Point origin = Point.FromLngLat(userLocation.Longitude, userLocation.Latitude);

            if (TurfMeasurement.Distance(origin, destination, TurfConstants.UnitMeters) < 50)
            {
                startRouteButton.Visibility = (ViewStates.Gone);
                return;
            }

            NavigationRoute.Builder navigationRouteBuilder = NavigationRoute.GetBuilder()
                                                             .AccessToken(Mapbox.AccessToken);

            navigationRouteBuilder.Origin(origin);
            navigationRouteBuilder.Destination(destination);
            if (waypoint != null)
            {
                navigationRouteBuilder.AddWaypoint(waypoint);
            }

            var directions = await navigationRouteBuilder.Build().GetRouteAsync();

            DirectionsRoute directionsRoute = directions.Routes()[0];

            route = directionsRoute;
            navigationMapRoute.AddRoutes(directions.Routes());
        }
Пример #5
0
 private void GetRoute(Point origin, Point destination)
 {
     NavigationRoute.InvokeBuilder(this)
     .Origin(origin)
     .Destination(destination)
     .AccessToken(Mapbox.Mapboxsdk.Mapbox.AccessToken)
     .Build().GetRoute(this);
 }
Пример #6
0
        public ActionResult DeleteConfirmed(int id)
        {
            NavigationRoute navigationroute = db.NavRoutes.Find(id);

            db.NavRoutes.Remove(navigationroute);
            db.SaveChanges();
            return(RedirectToAction("Index"));
        }
        public static Task <DirectionsResponse> GetRouteAsync(this NavigationRoute route)
        {
            var tcs = new TaskCompletionSource <DirectionsResponse>();

            route.GetRoute(new InternallCallback(tcs));

            return(tcs.Task);
        }
Пример #8
0
 public void FindRoute(Point origin, Point destination)
 {
     NavigationRoute.InvokeBuilder(this)
     .AccessToken(Mapbox.Mapboxsdk.Mapbox.AccessToken)
     .Origin(origin)
     .Destination(destination)
     .Alternatives((Java.Lang.Boolean)true)
     .Build()
     .GetRoute(this);
 }
Пример #9
0
 void GetRoute(Com.Mapbox.Geojson.Point origin, Com.Mapbox.Geojson.Point destination, double?bearing)
 {
     NavigationRoute
     .GetBuilder()
     .Origin(origin, bearing.HasValue ? new Java.Lang.Double(bearing.Value) : null, new Java.Lang.Double(90))
     .Destination(destination)
     .AccessToken(Mapbox.AccessToken)
     .Build()
     .GetRoute(this);
 }
Пример #10
0
        //
        // GET: /NavigationRoute/Delete/5

        public ActionResult Delete(int id = 0)
        {
            NavigationRoute navigationroute = db.NavRoutes.Find(id);

            if (navigationroute == null)
            {
                return(HttpNotFound());
            }
            return(View(navigationroute));
        }
Пример #11
0
 public ActionResult Edit(NavigationRoute navigationroute)
 {
     if (ModelState.IsValid)
     {
         db.Entry(navigationroute).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View(navigationroute));
 }
Пример #12
0
        public IEnumerable <NavigationRoute> DbRoutes()
        {
            IEnumerable <NavigationRoute> routes = Enumerable.Empty <NavigationRoute>();

            try
            {
                string connStr = _config.GetSection("Configuration").GetSection("ConnString").Value;
                using (SqlConnection conn = new SqlConnection(connStr))
                {
                    SqlCommand cmd = new SqlCommand();
                    conn.Open();
                    cmd             = new SqlCommand("SELECT Id, ParentId, Route, Name, Icon, ModuleId, Nav, Title FROM dbo.NavigationRoute order by Id", conn);
                    cmd.CommandType = CommandType.Text;
                    //cmd.Parameters.Add("@Type", SqlDbType.VarChar).Value = "appicon";

                    SqlDataReader reader = null;
                    reader = cmd.ExecuteReader();

                    while (reader.Read())
                    {
                        Object dbParentId = reader["ParentId"];
                        int?   parentId;

                        if ((dbParentId.GetType().ToString().Equals("System.DBNull")))
                        {
                            parentId = null;
                        }
                        else
                        {
                            parentId = Convert.ToInt16(dbParentId);
                        }

                        NavigationRoute route = new NavigationRoute
                        {
                            Id       = Convert.ToInt16(reader["Id"].ToString()),
                            ParentId = parentId,
                            Route    = reader["Route"].ToString(),
                            Name     = reader["Name"].ToString(),
                            Icon     = reader["Icon"].ToString(),
                            ModuleId = reader["ModuleId"].ToString(),
                            Nav      = (bool)reader["Nav"],
                            Title    = reader["Title"].ToString()
                        };

                        routes = routes.Concat(new[] { route });
                    }
                }
            }
            catch (SystemException ex)
            {
                return(this.DefaultRoutes());
            }

            return(routes);
        }
Пример #13
0
        public ActionResult Create(NavigationRoute navigationroute)
        {
            if (ModelState.IsValid)
            {
                db.NavRoutes.Add(navigationroute);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(navigationroute));
        }
        private void FetchRoute()
        {
            NavigationRoute builder = NavigationRoute.InvokeBuilder(this)
                                      .AccessToken(GetString(Resource.String.mapbox_access_token))
                                      .Origin(origin)
                                      .Destination(destination)
                                      .Alternatives((Java.Lang.Boolean)true)
                                      .Build();

            builder.GetRoute(this);
        }
Пример #15
0
        public override async Task <NavigationRoute> GetDirectionsAsync(GeoCoordinate currentLocation, GeoCoordinate destination, List <GeoCoordinate> optionalWaypoints = null)
        {
            string url = ConstructUrl(currentLocation, destination, GoogleDirectionsMode.Walking);

            if (_cache.ContainsKey(url))
            {
                _logger.Trace("Retrieving requested route from cache.");
                return(_cache[url]);
            }

            _logger.Trace("No cached route. Asking Google...");
            using (HttpResponseMessage responseMessage = await _httpClient.GetAsync(url))
            {
                if (!responseMessage.IsSuccessStatusCode)
                {
                    throw new Exception("Error on directions API call");
                }

                string payload = await responseMessage.Content.ReadAsStringAsync();

                GoogleDirectionsResponse directionsResponse = JsonConvert.DeserializeObject <GoogleDirectionsResponse>(payload);

                if (directionsResponse.Status != "OK")
                {
                    throw new Exception("Unexpected response from Google# 4193465");
                }

                if (directionsResponse.Routes.Count != 1 || directionsResponse.Routes[0].Legs.Count != 1)
                {
                    throw new Exception("unexpected response from Google #33593");
                }

                Leg leg = directionsResponse.Routes[0].Legs[0];

                NavigationRoute navigationRoute = new NavigationRoute();
                navigationRoute.Distance   = leg.distance.Value;
                navigationRoute.TravelTime = leg.duration.Value;

                List <GeoCoordinate> waypointsList = new List <GeoCoordinate>();
                foreach (Step step in leg.Steps)
                {
                    // get waypoints using Polylines within each step
                    IEnumerable <GeoCoordinate> waypoints = DecodePolyline(step.Polyline.Points);
                    waypointsList.AddRange(waypoints);
                }

                // clean up duplicates
                navigationRoute.Waypoints = waypointsList.Distinct().ToList();

                _cache.Add(url, navigationRoute);

                return(navigationRoute);
            }
        }
Пример #16
0
        // GET api/Navigation/5
        public NavigationRoute GetNavigationRoute(int id)
        {
            NavigationRoute navigationroute = db.NavRoutes.Find(id);

            if (navigationroute == null)
            {
                throw new HttpResponseException(Request.CreateResponse(HttpStatusCode.NotFound));
            }

            return(navigationroute);
        }
        public ActionResult Create(NavigationRoute navigationroute)
        {
            if (ModelState.IsValid)
            {
                db.NavRoutes.Add(navigationroute);
                db.SaveChanges();
                return RedirectToAction("Index");
            }

            return View(navigationroute);
        }
 private void FetchRoute()
 {
     NavigationRoute
     .GetBuilder()
     .AccessToken(Mapbox.AccessToken)
     .Origin(currentLocation)
     .Destination(destination)
     .Alternatives(new Java.Lang.Boolean(true))
     .Build()
     .GetRoute(this);
     loading.Visibility = (ViewStates.Visible);
 }
Пример #19
0
        private void CalculateRouteWith(Point destination, bool isOffRoute)
        {
            Point  origin  = Point.FromLngLat(lastLocation.Longitude, lastLocation.Latitude);
            double bearing = (double)lastLocation.Bearing;

            NavigationRoute.InvokeBuilder(this)
            .AccessToken(Mapbox.Mapboxsdk.Mapbox.AccessToken)
            .Origin(origin, (Java.Lang.Double)bearing, (Java.Lang.Double)BEARING_TOLERANCE)
            .Destination(destination)
            .Build()
            .GetRoute(new SimplifiedCallback((response) =>
            {
                HandleRoute(response, isOffRoute);
            }));
        }
Пример #20
0
        private void FetchRoute()
        {
            NavigationRoute builder = NavigationRoute.InvokeBuilder(this)
                                      .AccessToken(Mapbox.Mapboxsdk.Mapbox.AccessToken)
                                      .Origin(origin)
                                      .Profile(DirectionsCriteria.ProfileDriving)
                                      .AddWaypoint(pickup)
                                      .AddWaypoint(middlePickup)
                                      .Destination(destination)
                                      .AddWaypointIndices(new Integer(0), new Integer(2), new Integer(3))
                                      .Alternatives((Java.Lang.Boolean)true)
                                      .Build();

            builder.GetRoute(this);
            UpdateLoadingTo(true);
        }
Пример #21
0
        // POST api/Navigation
        public HttpResponseMessage PostNavigationRoute(NavigationRoute navigationroute)
        {
            if (ModelState.IsValid)
            {
                db.NavRoutes.Add(navigationroute);
                db.SaveChanges();

                HttpResponseMessage response = Request.CreateResponse(HttpStatusCode.Created, navigationroute);
                response.Headers.Location = new Uri(Url.Link("DefaultApi", new { id = navigationroute.Id }));
                return(response);
            }
            else
            {
                return(Request.CreateResponse(HttpStatusCode.BadRequest));
            }
        }
        // POST api/Navigation
        public HttpResponseMessage PostNavigationRoute(NavigationRoute navigationroute)
        {
            if (ModelState.IsValid)
            {
                db.NavRoutes.Add(navigationroute);
                db.SaveChanges();

                HttpResponseMessage response = Request.CreateResponse(HttpStatusCode.Created, navigationroute);
                response.Headers.Location = new Uri(Url.Link("DefaultApi", new { id = navigationroute.Id }));
                return response;
            }
            else
            {
                return Request.CreateResponse(HttpStatusCode.BadRequest);
            }
        }
        async void BuildRoute()
        {
            MapboxNavigation navigation = new MapboxNavigation(this, MAPBOX_KEY);

            Point origin      = Point.FromLngLat(-77.03613, 38.90992);
            Point destination = Point.FromLngLat(-77.0365, 38.8977);

            var response = await NavigationRoute
                           .GetBuilder()
                           .AccessToken(Mapbox.AccessToken)
                           .Origin(origin)
                           .Destination(destination)
                           .Build()
                           .GetRouteAsync();

            System.Diagnostics.Debug.WriteLine(response);
        }
Пример #24
0
 private void FetchRoute(Point origin, Point destination)
 {
     NavigationRoute.InvokeBuilder(this)
     .AccessToken(Mapbox.Mapboxsdk.Mapbox.AccessToken)
     .Origin(origin)
     .Destination(destination)
     .Alternatives((Java.Lang.Boolean)true)
     .Build()
     .GetRoute(new SimplifiedCallback((res) =>
     {
         var body = res.Body() as DirectionsResponse;
         if (body != null && body.Routes().Any())
         {
             StartNavigation(body.Routes()[0]);
         }
     }));
 }
 private void FetchRoute(Point origin, Point destination)
 {
     NavigationRoute.InvokeBuilder(Context)
     .AccessToken(Mapbox.Mapboxsdk.Mapbox.AccessToken)
     .Origin(origin)
     .Destination(destination)
     .Build()
     .GetRoute(new SimplifiedCallback((response) =>
     {
         var body = response.Body() as DirectionsResponse;
         if (body != null && body.Routes().Any())
         {
             directionsRoute = body.Routes()[0];
             StartNavigation();
         }
     }));
 }
Пример #26
0
        public IEnumerable <NavigationRoute> DefaultRoutes()
        {
            IEnumerable <NavigationRoute> routes = Enumerable.Empty <NavigationRoute>();

            var route1 = new NavigationRoute
            {
                Id       = 1,
                Route    = "scheduler",
                Name     = "scheduler",
                Icon     = "education",
                ModuleId = "../scheduler/scheduler",
                Nav      = true,
                Title    = "Scheduler"
            };

            var route2 = new NavigationRoute
            {
                Id       = 2,
                Route    = "counter",
                Name     = "counter",
                Icon     = "education",
                ModuleId = "../counter/counter",
                Nav      = true,
                Title    = "Counter"
            };

            var route3 = new NavigationRoute
            {
                Id       = 3,
                Route    = "fetch-data",
                Name     = "fetchdata",
                Icon     = "th-list",
                ModuleId = "../fetchdata/fetchdata",
                Nav      = true,
                Title    = "Fetch data"
            };

            routes = routes.Concat(new[] { route1 });
            routes = routes.Concat(new[] { route2 });
            routes = routes.Concat(new[] { route3 });

            return(routes);
        }
        // PUT api/Navigation/5
        public HttpResponseMessage PutNavigationRoute(int id, NavigationRoute navigationroute)
        {
            if (ModelState.IsValid && id == navigationroute.Id)
            {
                db.Entry(navigationroute).State = EntityState.Modified;

                try
                {
                    db.SaveChanges();
                }
                catch (DbUpdateConcurrencyException)
                {
                    return Request.CreateResponse(HttpStatusCode.NotFound);
                }

                return Request.CreateResponse(HttpStatusCode.OK);
            }
            else
            {
                return Request.CreateResponse(HttpStatusCode.BadRequest);
            }
        }
Пример #28
0
        // DELETE api/Navigation/5
        public HttpResponseMessage DeleteNavigationRoute(int id)
        {
            NavigationRoute navigationroute = db.NavRoutes.Find(id);

            if (navigationroute == null)
            {
                return(Request.CreateResponse(HttpStatusCode.NotFound));
            }

            db.NavRoutes.Remove(navigationroute);

            try
            {
                db.SaveChanges();
            }
            catch (DbUpdateConcurrencyException)
            {
                return(Request.CreateResponse(HttpStatusCode.NotFound));
            }

            return(Request.CreateResponse(HttpStatusCode.OK, navigationroute));
        }
Пример #29
0
        // PUT api/Navigation/5
        public HttpResponseMessage PutNavigationRoute(int id, NavigationRoute navigationroute)
        {
            if (ModelState.IsValid && id == navigationroute.Id)
            {
                db.Entry(navigationroute).State = EntityState.Modified;

                try
                {
                    db.SaveChanges();
                }
                catch (DbUpdateConcurrencyException)
                {
                    return(Request.CreateResponse(HttpStatusCode.NotFound));
                }

                return(Request.CreateResponse(HttpStatusCode.OK));
            }
            else
            {
                return(Request.CreateResponse(HttpStatusCode.BadRequest));
            }
        }
Пример #30
0
        }                                                    // in km/h

        public async Task Move(NavigationRoute navigationRoute)
        {
            if (navigationRoute == null || navigationRoute.Waypoints.Count == 0)
            {
                throw new ArgumentException("no route or no waypoints!");
            }

            if (Math.Abs(MovementSpeed) < 0)
            {
                throw new Exception("Moving at the speed of lig... ZERO! 0.0!");
            }

            _navigationRoute = navigationRoute;

            while (_navigationRoute.Waypoints.Count >= 2)
            {
                GeoCoordinate startingLocation    = _navigationRoute.Waypoints[0];
                GeoCoordinate destinationLocation = _navigationRoute.Waypoints[1];

                double bearing = CalculateBearing(startingLocation, destinationLocation);
                if (double.IsNaN(bearing))
                {
                    _navigationRoute.Waypoints.RemoveAt(0);
                    continue;
                }

                await DoMinorSteps(startingLocation, destinationLocation, bearing);

                _navigationRoute.Waypoints.RemoveAt(0);

                // remove last element (you reached your destination)
                if (_navigationRoute.Waypoints.Count == 1)
                {
                    _navigationRoute.Waypoints.Clear();
                }
            }
        }
        private void FindRouteWith(LocationEngineResult result)
        {
            Location userLocation = result.LastLocation;

            if (userLocation == null)
            {
                Timber.D("calculateRoute: User location is null, therefore, origin can't be set.");
                return;
            }
            Point origin = Point.FromLngLat(userLocation.Longitude, userLocation.Latitude);

            if (TurfMeasurement.Distance(origin, destination, TurfConstants.UnitMeters) < 50)
            {
                startRouteButton.Visibility = ViewStates.Gone;
                return;
            }

            NavigationRoute.Builder navigationRouteBuilder = NavigationRoute.InvokeBuilder(this)
                                                             .AccessToken(Mapbox.Mapboxsdk.Mapbox.AccessToken);
            navigationRouteBuilder.Origin(origin);
            navigationRouteBuilder.Destination(destination);
            if (waypoint != null)
            {
                navigationRouteBuilder.AddWaypoint(waypoint);
            }
            navigationRouteBuilder.EnableRefresh(true);
            navigationRouteBuilder.Build().GetRoute(new GetRouteCallback((response) =>
            {
                if (response != null && response.Routes().Any())
                {
                    route = response.Routes()[0];
                    navigationMapRoute.AddRoutes(response.Routes());
                    startRouteButton.Visibility = ViewStates.Visible;
                }
            }));
        }
Пример #32
0
        public async Task Run(CancellationToken cancellationToken)
        {
            cancellationToken.ThrowIfCancellationRequested();

            // TODO: Provide initial location
            GeoCoordinate currentLocation = new GeoCoordinate(48.642050, 9.458333);

            // Provide "fuzzy" movement observer
            //FuzzyLocationFeed fuzzyLocationFeed = new FuzzyLocationFeed(currentLocation, _moveStrategy, 10);
            TestLocationObserver testLocationObserver = new TestLocationObserver("test1");
            //IDisposable testLocationObserver1Subscription = fuzzyLocationFeed.Subscribe(testLocationObserver);
            var testLocationObserver1Subscription = _moveStrategy.Subscribe(testLocationObserver);

            Task movement = Task.Run(
                async() =>
            {
                while (true)
                {
                    _logger.Trace("walking...");

                    // simulate POIModule
                    PointOfInterest pointOfInterest = _poiProvider.GetPointOfInterest();
                    _logger.Trace(
                        "(POI) {0} ({1}, {2})", pointOfInterest.Name, pointOfInterest.Location.Latitude, pointOfInterest.Location.Longitude);

                    // get route to POI
                    NavigationRoute navigationRoute = await _navigator.GetDirectionsAsync(currentLocation, pointOfInterest.Location);
                    _logger.Trace(
                        "(NAV) Found a route to {0}. Let's go ({1}m, {2}s)", pointOfInterest.Name, navigationRoute.Distance,
                        navigationRoute.TravelTime);

                    // move
                    await _moveStrategy.Move(navigationRoute);
                }
            }, cancellationToken);

            Task action = Task.Run(
                async() =>
            {
                while (true)
                {
                    int x = new Random().Next(0, 1000);
                    if (x % 13 == 0)
                    {
                        _logger.Trace("Set movement speed 0!");
                        _moveStrategy.SetMovementSpeed(0);

                        await Task.Delay(10000, cancellationToken);
                    }
                    else if (x % 17 == 0)
                    {
                        _logger.Trace("Set movement speed 20!");
                        _moveStrategy.SetMovementSpeed(20);
                    }

                    await Task.Delay(1000, cancellationToken);
                }
            }, cancellationToken);

            await Task.WhenAll(movement, action);

            testLocationObserver1Subscription.Dispose();
        }
 public ActionResult Edit(NavigationRoute navigationroute)
 {
     if (ModelState.IsValid)
     {
         db.Entry(navigationroute).State = EntityState.Modified;
         db.SaveChanges();
         return RedirectToAction("Index");
     }
     return View(navigationroute);
 }