예제 #1
0
        public async void OnLocationChanged(Android.Locations.Location location)
        {
            //mLastLocation = location;
            System.Diagnostics.Debug.WriteLine("location");
            DateTime now         = DateTime.Now.ToLocalTime();
            string   currentTime = (string.Format("{0}", now));

            HaxOnTheWay.Models.Location      Longitud = new HaxOnTheWay.Models.Location();
            HaxOnTheWay.Services.RestService Services = new HaxOnTheWay.Services.RestService();

            Longitud.Long = (float)location.Longitude;
            Longitud.Lat  = (float)location.Latitude;
            Longitud.time = currentTime;

            var instanceID = FirebaseInstanceId.Instance;
            //instanceID.DeleteInstanceId();
            var iid1 = instanceID.Token;

            //var iid2 = instanceID.GetToken("haxontheway", Firebase.Messaging.FirebaseMessaging.InstanceIdScope);
            //System.Diagnostics.Debug.WriteLine("token ss" + iid1);

            Longitud.sToken = iid1;
            if (HaxOnTheWay.Helpers.Settings.IsLoggedIn)
            {
                if (!isStartedF)
                {
                    isStartedF = true;
                    RegisterForegroundService();
                }
                List <Drivers> requestCommands = await App.Database.GetAllDriversAsync();

                //List<dataSourceCommands> reqestSourceCommand = new List<dataSourceCommands>();

                foreach (Drivers item in requestCommands)
                {
                    //dataSourceCommands items = new dataSourceCommands();
                    Longitud.idConductor = item.iDriver;
                    idConductor          = item.iDriver;
                }

                Longitud.indConnect = 1;
                estatus_ind         = true;
                //SendLocation(Longitud);
                try
                {
                    await Services.SendLocation(Longitud);
                }
                catch (Java.Lang.Exception e)
                {
                    System.Diagnostics.Debug.WriteLine("error location : " + e.Message.ToString());
                }
            }
            else
            {
                if (estatus_ind)
                {
                    Longitud.idConductor = idConductor;
                    Longitud.indConnect  = 0;
                    estatus_ind          = false;
                    try
                    {
                        await Services.SendLocation(Longitud);
                    }
                    catch (Java.Lang.Exception e)
                    {
                        System.Diagnostics.Debug.WriteLine(e.Message.ToString());
                    }
                    StopForeground(true);
                    //StopSelf();
                    //isStarted = false;
                    isStartedF = false;
                }
            }
        }
예제 #2
0
        // ILocationListener is a way for the Service to subscribe for updates
        // from the System location Service

        public async void OnLocationChanged(Android.Locations.Location location)
        {
            System.Diagnostics.Debug.WriteLine("location");
            this.LocationChanged(this, new LocationChangedEventArgs(location));

            DateTime now         = DateTime.Now.ToLocalTime();
            string   currentTime = (string.Format("{0}", now));

            // This should be updating every time we request new location updates
            // both when teh app is in the background, and in the foreground
            HaxOnTheWay.Models.Location      Longitud = new HaxOnTheWay.Models.Location();
            HaxOnTheWay.Services.RestService Services = new HaxOnTheWay.Services.RestService();

            Longitud.Long = (float)location.Longitude;
            Longitud.Lat  = (float)location.Latitude;
            Longitud.time = currentTime;

            var instanceID = FirebaseInstanceId.Instance;
            //instanceID.DeleteInstanceId();
            var iid1 = instanceID.Token;

            //var iid2 = instanceID.GetToken("haxontheway", Firebase.Messaging.FirebaseMessaging.InstanceIdScope);
            //System.Diagnostics.Debug.WriteLine("token ss" + iid1);

            Longitud.sToken = iid1;
            if (Settings.IsLoggedIn)
            {
                List <Drivers> requestCommands = await App.Database.GetAllDriversAsync();

                //List<dataSourceCommands> reqestSourceCommand = new List<dataSourceCommands>();

                foreach (Drivers item in requestCommands)
                {
                    //dataSourceCommands items = new dataSourceCommands();
                    Longitud.idConductor = item.iDriver;
                    idConductor          = item.iDriver;
                }

                Longitud.indConnect = 1;
                estatus_ind         = true;
                //SendLocation(Longitud);
                try{
                    await Services.SendLocation(Longitud);
                }catch (Exception e) {
                    System.Diagnostics.Debug.WriteLine("error location : " + e.Message.ToString());
                }
            }
            else
            {
                if (estatus_ind)
                {
                    Longitud.idConductor = idConductor;
                    Longitud.indConnect  = 0;
                    estatus_ind          = false;
                    try{
                        await Services.SendLocation(Longitud);
                    }catch (Exception e) {
                        System.Diagnostics.Debug.WriteLine(e.Message.ToString());
                    }
                }
            }

            Log.Debug(logTag, String.Format("Latitude is {0}", location.Latitude));
            Log.Debug(logTag, String.Format("Longitude is {0}", location.Longitude));
            Log.Debug(logTag, String.Format("Altitude is {0}", location.Altitude));
            Log.Debug(logTag, String.Format("Speed is {0}", location.Speed));
            Log.Debug(logTag, String.Format("Accuracy is {0}", location.Accuracy));
            Log.Debug(logTag, String.Format("Bearing is {0}", location.Bearing));
        }