Пример #1
0
        static void Main(string[] args)
        {
            string dbPath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Desktop), "SimpleGps.db");


            SQLiteConnection databaseConnection = new SQLiteConnection(dbPath);

            databaseConnection.CreateTable <SimpleGpsLocation>();
            databaseConnection.CreateTable <SimpleGpsRoute>();

            var routes = databaseConnection.Table <SimpleGpsRoute>()
                         .ToList();

            for (int i = routes.Count - 1; i > routes.Count - 3; i--)
            {
                SimpleGpsRoute            item   = routes[i];
                IEnumerable <gpxTrkTrkpt> points = databaseConnection.Table <SimpleGpsLocation>().Where(x => x.SimpleGpsRouteId == item.Id)
                                                   .ToList()
                                                   .Select(x => new gpxTrkTrkpt()
                {
                    ele  = x.Altitude,  //.ToString("F1"),
                    lat  = x.Latitude,  //.ToString("F7"),
                    lon  = x.Longitude, //.ToString("F7"),
                    time = x.DateTime,  //.ToString("u").Replace(' ', 'T')
                });

                var exportdata = new gpx()
                {
                    creator  = "com.mihyan.simpletracker",
                    version  = 1.1m,
                    metadata = new gpxMetadata()
                    {
                        link = new gpxMetadataLink()
                        {
                            href = "http://localhost:8080", text = "localhost"
                        },
                        time = points.OrderBy(x => x.time).First().time,
                    },
                    trk = new gpxTrk()
                    {
                        name   = "[Simple tracker]",
                        trkseg = points.ToArray(),
                    }
                };

                string destination = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Desktop), $"route{i + 1}.gpx");

                XmlWriterSettings settings = new XmlWriterSettings()
                {
                    Indent          = true,
                    NewLineHandling = NewLineHandling.Replace
                };


                //using XmlWriter writer = XmlWriter.Create(destination, new XmlWriterSettings());
                new XmlSerializer(exportdata.GetType())
                .Serialize(new StreamWriter(destination), exportdata);
            }
        }
Пример #2
0
        private void RegisterService()
        {
            if (this.isStarted)
            {
                return;
            }

            this.isStarted = true;

            // The constructor is deprecated, but it's necessary for old androids.
            this.notification = new Notification.Builder(this)
                                .SetContentTitle("SimpleTracker recording...")
                                .SetContentText($"Distance {this.distanceTraveled / 1000:N3} km")
                                .SetSmallIcon(Resource.Drawable.Image) // This is required, otherwise default system text and message are displayed
                                .SetOngoing(true);

            StartForeground(GpsNotificationId, this.notification.Build());

            SimpleGpsRoute route = new SimpleGpsRoute()
            {
                Name = $"Route: {DateTime.Now.ToShortDateString()} {DateTime.Now.ToShortTimeString()}"
            };

            this.database.Add(route);

            this.currentRouteId = route.Id;

            this.gpsListener.PositionChanged  += Current_PositionChanged;
            this.gpsListener.ProviderDisabled += GpsListener_ProviderDisabled;
            this.gpsManager.RequestLocationUpdates(LocationManager.GpsProvider, minTime: 1000, minDistance: 5, this.gpsListener);

            // This is how to update a notification text

            /*
             * notification
             *  .SetContentText("UpdatedText");
             *
             *  notificationManager.Notify(GpsNotificationId, notification.Build());
             */
        }