コード例 #1
0
        public void SetGPSPosition(string routeId)
        {
            // Create the manager with the api key
            Route4MeManager route4Me = new Route4MeManager(c_ApiKey);

            // Create the gps parametes
            GPSParameters gpsParameters = new GPSParameters()
            {
                Format          = Format.Csv.Description(),
                RouteId         = routeId,
                Latitude        = 33.14384,
                Longitude       = -83.22466,
                Course          = 1,
                Speed           = 120,
                DeviceType      = DeviceType.IPhone.Description(),
                MemberId        = 1,
                DeviceGuid      = "TEST_GPS",
                DeviceTimestamp = "2014-06-14 17:43:35"
            };

            string errorString;
            string response = route4Me.SetGPS(gpsParameters, out errorString);

            Console.WriteLine("");

            if (string.IsNullOrEmpty(errorString))
            {
                Console.WriteLine("SetGps response: {0}", response);
            }
            else
            {
                Console.WriteLine("SetGps error: {0}", errorString);
            }
        }
コード例 #2
0
        /// <summary>
        /// The example refers to the process of setting the GPS position of a device.
        /// </summary>
        public void SetGPSPosition()
        {
            // Create the manager with the api key
            var route4Me = new Route4MeManager(ActualApiKey);

            RunOptimizationSingleDriverRoute10Stops();
            OptimizationsToRemove = new List <string>();
            OptimizationsToRemove.Add(SD10Stops_optimization_problem_id);

            double lat = SD10Stops_route.Addresses.Length > 1
                ? SD10Stops_route.Addresses[1].Latitude
                : 33.14384;
            double lng = SD10Stops_route.Addresses.Length > 1
                ? SD10Stops_route.Addresses[1].Longitude
                : -83.22466;

            // Create the gps parameters
            var gpsParameters = new GPSParameters()
            {
                Format          = Format.Csv.Description(),
                RouteId         = SD10Stops_route_id,
                Latitude        = lat,
                Longitude       = lng,
                Course          = 1,
                Speed           = 120,
                DeviceType      = DeviceType.IPhone.Description(),
                MemberId        = (int)SD10Stops_route.Addresses[1].MemberId,
                DeviceGuid      = "TEST_GPS",
                DeviceTimestamp = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")
            };

            // Run query
            var response = route4Me.SetGPS(gpsParameters, out string errorString);

            Console.WriteLine("");

            Console.WriteLine(
                string.IsNullOrEmpty(errorString)
                ? String.Format("SetGps response: {0}", response.ToString())
                : String.Format("SetGps error: {0}", errorString)
                );

            RemoveTestOptimizations();
        }
コード例 #3
0
        /// <summary>
        /// The example refers to the process of getting the last location history of a GPS device.
        /// </summary>
        public void TrackDeviceLastLocationHistory()
        {
            // Create the manager with the api key
            var route4Me = new Route4MeManager(ActualApiKey);

            #region Create GPS event record

            var      tsp2days = new TimeSpan(2, 0, 0, 0);
            DateTime dtNow    = DateTime.Now;

            RunOptimizationSingleDriverRoute10Stops();
            OptimizationsToRemove = new List <string>();
            OptimizationsToRemove.Add(SD10Stops_optimization_problem_id);

            double lat = SD10Stops_route.Addresses.Length > 1
                ? SD10Stops_route.Addresses[1].Latitude
                : 33.14384;
            double lng = SD10Stops_route.Addresses.Length > 1
                ? SD10Stops_route.Addresses[1].Longitude
                : -83.22466;

            var gpsParameters = new GPSParameters
            {
                Format          = Format.Csv.Description(),
                RouteId         = SD10Stops_route_id,
                Latitude        = lat,
                Longitude       = lng,
                Course          = 1,
                Speed           = 120,
                DeviceType      = DeviceType.IPhone.Description(),
                MemberId        = (int)SD10Stops_route.Addresses[1].MemberId,
                DeviceGuid      = "TEST_GPS",
                DeviceTimestamp = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")
            };

            var response = route4Me.SetGPS(gpsParameters, out string errorString);

            if (!string.IsNullOrEmpty(errorString))
            {
                Console.WriteLine("SetGps error: {0}", errorString);
                return;
            }

            Console.WriteLine("SetGps response: {0}", response.Status.ToString());

            #endregion

            var trParameters = new RouteParametersQuery()
            {
                RouteId = SD10Stops_route_id,
                DeviceTrackingHistory = true
            };

            var dataObject = route4Me.GetLastLocation(trParameters, out errorString);

            Console.WriteLine("");

            if (dataObject != null)
            {
                Console.WriteLine("TrackDeviceLastLocationHistory executed successfully");
                Console.WriteLine("");

                Console.WriteLine("Optimization Problem ID: {0}", dataObject.OptimizationProblemId);
                Console.WriteLine("");

                dataObject.TrackingHistory.ForEach(th =>
                {
                    Console.WriteLine("Speed: {0}", th.Speed);
                    Console.WriteLine("Longitude: {0}", th.Longitude);
                    Console.WriteLine("Latitude: {0}", th.Latitude);
                    Console.WriteLine("Time Stamp: {0}", th.TimeStampFriendly);
                    Console.WriteLine("");
                });
            }
            else
            {
                Console.WriteLine("TrackDeviceLastLocationHistory error: {0}", errorString);
            }

            RemoveTestOptimizations();
        }
コード例 #4
0
        /// <summary>
        /// Get Device History from Time Range
        /// </summary>
        public void GetDeviceHistoryTimeRange()
        {
            // Create the manager with the api key
            var route4Me = new Route4MeManager(ActualApiKey);

            #region Create GPS event record

            var      tsp2days = new TimeSpan(2, 0, 0, 0);
            DateTime dtNow    = DateTime.Now;

            RunOptimizationSingleDriverRoute10Stops();
            OptimizationsToRemove = new List <string>();
            OptimizationsToRemove.Add(SD10Stops_optimization_problem_id);

            double lat = SD10Stops_route.Addresses.Length > 1
                ? SD10Stops_route.Addresses[1].Latitude
                : 33.14384;
            double lng = SD10Stops_route.Addresses.Length > 1
                ? SD10Stops_route.Addresses[1].Longitude
                : -83.22466;

            var gpsParameters = new GPSParameters
            {
                Format          = Format.Csv.Description(),
                RouteId         = SD10Stops_route_id,
                Latitude        = lat,
                Longitude       = lng,
                Course          = 1,
                Speed           = 120,
                DeviceType      = DeviceType.IPhone.Description(),
                MemberId        = (int)SD10Stops_route.Addresses[1].MemberId,
                DeviceGuid      = "TEST_GPS",
                DeviceTimestamp = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")
            };

            var response = route4Me.SetGPS(gpsParameters, out string errorString);

            if (!string.IsNullOrEmpty(errorString))
            {
                Console.WriteLine("SetGps error: {0}", errorString);
                return;
            }

            Console.WriteLine("SetGps response: {0}", response.Status.ToString());

            #endregion

            var trParameters = new GPSParameters
            {
                Format     = "json",
                RouteId    = SD10Stops_route_id,
                TimePeriod = "custom",
                StartDate  = R4MeUtils.ConvertToUnixTimestamp(dtNow - tsp2days),
                EndDate    = R4MeUtils.ConvertToUnixTimestamp(dtNow + tsp2days)
            };

            var result = route4Me.GetDeviceLocationHistory(trParameters, out errorString);

            Console.WriteLine(
                result != null && result.GetType() == typeof(DeviceLocationHistoryResponse)
                    ? "GetDeviceHistoryTimeRangeTest executed successfully"
                    : "GetDeviceHistoryTimeRangeTest failed. " + errorString
                );

            if (result != null && result.GetType() == typeof(DeviceLocationHistoryResponse))
            {
                Console.WriteLine("");

                var locationHistoryResul = (DeviceLocationHistoryResponse)result;

                if ((locationHistoryResul.data?.Length ?? 0) > 0)
                {
                    foreach (var locationHistory in locationHistoryResul.data)
                    {
                        Console.WriteLine("Location: {0}, {1}", locationHistory.Latitude, locationHistory.Longitude);
                    }
                }
            }

            RemoveTestOptimizations();
        }
        public void TrackDeviceLastLocationHistory(string routeId)
        {
            // Create the manager with the api key
            Route4MeManager route4Me = new Route4MeManager(c_ApiKey);

            // Create the gps parametes
            GPSParameters gpsParameters = new GPSParameters()
            {
                Format          = Format.Csv.Description(),
                RouteId         = routeId,
                Latitude        = 33.14384,
                Longitude       = -83.22466,
                Course          = 1,
                Speed           = 120,
                DeviceType      = DeviceType.IPhone.Description(),
                MemberId        = 1,
                DeviceGuid      = "TEST_GPS",
                DeviceTimestamp = "2014-06-14 17:43:35"
            };

            string errorString;
            string response = route4Me.SetGPS(gpsParameters, out errorString);

            if (!string.IsNullOrEmpty(errorString))
            {
                Console.WriteLine("SetGps error: {0}", errorString);
                return;
            }

            Console.WriteLine("SetGps response: {0}", response);

            GenericParameters genericParameters = new GenericParameters();

            genericParameters.ParametersCollection.Add("route_id", routeId);
            genericParameters.ParametersCollection.Add("device_tracking_history", "1");

            var dataObject = route4Me.GetLastLocation(genericParameters, out errorString);

            Console.WriteLine("");

            if (dataObject != null)
            {
                Console.WriteLine("TrackDeviceLastLocationHistory executed successfully");
                Console.WriteLine("");

                Console.WriteLine("Optimization Problem ID: {0}", dataObject.OptimizationProblemId);
                Console.WriteLine("State: {0}", dataObject.State);
                Console.WriteLine("");

                dataObject.TrackingHistory.ForEach(th =>
                {
                    Console.WriteLine("Speed: {0}", th.Speed);
                    Console.WriteLine("Longitude: {0}", th.Longitude);
                    Console.WriteLine("Latitude: {0}", th.Latitude);
                    Console.WriteLine("Time Stamp: {0}", th.TimeStampFriendly);
                    Console.WriteLine("");
                });
            }
            else
            {
                Console.WriteLine("TrackDeviceLastLocationHistory error: {0}", errorString);
            }
        }
コード例 #6
0
        /// <summary>
        /// Get Device History from Time Range
        /// </summary>
        public void GetDeviceHistoryTimeRange(string routeId)
        {
            // Create the manager with the api key
            Route4MeManager route4Me = new Route4MeManager(c_ApiKey);

            int uStartTime = 0;
            int uEndTime   = 0;

            uStartTime = (int)(new DateTime(2016, 10, 20, 0, 0, 0) - (new DateTime(1970, 1, 1, 0, 0, 0))).TotalSeconds;
            uEndTime   = (int)(new DateTime(2016, 10, 26, 23, 59, 59) - (new DateTime(1970, 1, 1, 0, 0, 0))).TotalSeconds;

            GPSParameters gpsParameters = new GPSParameters
            {
                Format      = "csv",
                RouteId     = routeId,
                time_period = "custom",
                start_date  = uStartTime,
                end_date    = uEndTime
            };

            string errorString = "";
            string response    = route4Me.SetGPS(gpsParameters, out errorString);

            if (!string.IsNullOrEmpty(errorString))
            {
                Console.WriteLine("SetGps error: {0}", errorString);
                return;
            }

            Console.WriteLine("SetGps response: {0}", response);

            GenericParameters genericParameters = new GenericParameters();

            genericParameters.ParametersCollection.Add("route_id", routeId);
            genericParameters.ParametersCollection.Add("device_tracking_history", "1");

            var dataObject = route4Me.GetLastLocation(genericParameters, out errorString);

            Console.WriteLine("");

            if (dataObject != null)
            {
                Console.WriteLine("GetDeviceHistoryTimeRange executed successfully");
                Console.WriteLine("");

                Console.WriteLine("Optimization Problem ID: {0}", dataObject.OptimizationProblemId);
                Console.WriteLine("State: {0}", dataObject.State);
                Console.WriteLine("");
                foreach (TrackingHistory th in dataObject.TrackingHistory)
                {
                    Console.WriteLine("Speed: {0}", th.Speed);
                    Console.WriteLine("Longitude: {0}", th.Longitude);
                    Console.WriteLine("Latitude: {0}", th.Latitude);
                    Console.WriteLine("Time Stamp: {0}", th.TimeStampFriendly);
                    Console.WriteLine("");
                }
            }
            else
            {
                Console.WriteLine("GetDeviceHistoryTimeRange error: {0}", errorString);
            }
        }