Пример #1
0
        public string updaterecord(record theRecord, bool isConnected)
        {
            string status = "";

            if (isConnected)
            {
                if (offlineRecords.Count > 0)
                {
                    dumpOffLineRecords();
                    status = "backFromOffline";
                }

                try{
                    svc.updateMomgoData(theRecord.fullName, String.Format("{0},{1}", theRecord.lati, theRecord.longti), theRecord.date, true, theRecord.deviceId, theRecord.speed, true, theRecord.athid, theRecord.country, theRecord.distance, true, theRecord.gainedAlt, true, theRecord.bearinng, true, theRecord.recordType, true, theRecord.sportType, Constants.SPEC_GROUP_TYPE);
                }
                catch
                {
                    return("offline");
                }

                return(status);
            }
            else
            {
                offlineRecords.Add(theRecord);
                return("offline");
            }
        }
Пример #2
0
        public void OnLocationChanged(Location location)
        {
            string status = "online";

            //        if (!isStarted)
            //        {
            //            _title.Text = "Nitro ready...";
            //            _speedText.Text = "0.0";
            //            _altitudeText.Text = "0.0";
            //            _distance.Text = "0.0";
            //return;
            //        }

            _currentLocation = location;

            try
            {
                RunOnUiThread(() =>
                {
                    if (_currentLocation == null)
                    {
                        _title.Text = "Unable to determine your location.";
                    }
                    else
                    {
                        _title.Text = "On the go";

                        //if (!isPaused)
                        {
                            if (_lastLocation != null)
                            {
                                dist = contextPref.GetFloat("dist", 0f) + _currentLocation.DistanceTo(_lastLocation) / 1000;
                            }
                            lastAlt    = contextPref.GetFloat("lastAlt", 0f);
                            float dAlt = difAlt(lastAlt, float.Parse(_currentLocation.Altitude.ToString()));
                            if (dAlt < 4)
                            {
                                gainAlt = gainAlt + dAlt;
                            }

                            contextPrefEdit.PutFloat("gainAlt", gainAlt).Commit();
                        }

                        if (pType == (int)RIDE_TYPE.bike)
                        {
                            _speedText.Text = (_currentLocation.Speed * 3.6f).ToString("0.00");
                            btnLapDist.Text = "Lap distance : " + (dist % 5).ToString("0.00");
                            if (dist % 5 < 0.01)
                            {
                                if (DateTime.Now - tempTime > ts)
                                {
                                    tempTime = DateTime.Now;
                                    vibrate(1000);
                                }
                            }
                        }
                        if (pType == (int)RIDE_TYPE.run)
                        {
                            _speedText.Text = (16.6666 / (_currentLocation.Speed)).ToString("0.00");
                            btnLapDist.Text = "Lap distance : " + (dist % 1).ToString("0.00");
                            if (dist % 1 < 0.01)
                            {
                                if (DateTime.Now - tempTime > ts)
                                {
                                    tempTime = DateTime.Now;
                                    vibrate(1000);
                                }
                            }
                        }
                        if (_currentLocation.Speed < 0.1)
                        {
                            _speedText.Text = "0.00";
                        }

                        _altitudeText.Text = gainAlt.ToString("0.00");
                        _distance.Text     = (dist).ToString("0.00");

                        //if (!isPaused)
                        {
                            var name                  = MemberModel.firstname + " " + MemberModel.lastname;
                            DateTime dt               = DateTime.Now;
                            float speed               = float.Parse(_currentLocation.Speed.ToString()) * 3.6f;
                            var country               = MemberModel.country;
                            record merecord           = new record(name, _currentLocation.Latitude, _currentLocation.Longitude, dt, AppSettings.DeviceUDID, AppSettings.UserID, country, dist, speed, gainAlt, _currentLocation.Bearing, 0, pType.ToString());
                            handleRecord updateRecord = new handleRecord();
                            status = updateRecord.updaterecord(merecord, IsNetEnable());                            //the record and is there internet connection

                            //mMapView.AnimateCamera(CameraUpdateFactory.NewCameraPosition(new CameraPosition(new LatLng(_currentLocation.Latitude, _currentLocation.Longitude), Constants.MAP_ZOOM_LEVEL, 45f, _currentLocation.Bearing)));
                            SetMapPosition(new LatLng(_currentLocation.Latitude, _currentLocation.Longitude), _currentLocation.Bearing);
                        }

                        _lastLocation = _currentLocation;
                        contextPrefEdit.PutFloat("lastAlt", float.Parse(_currentLocation.Altitude.ToString())).Commit();
                        contextPrefEdit.PutFloat("dist", dist).Commit();
                        if (fFlag == 1 || status == "backFromOffline")
                        {
                            status = "online";
                        }
                        fFlag = 0;
                    }
                });
            }
            catch (Exception err)
            {
                //Toast.MakeText(this, err.ToString(), ToastLength.Long).Show();
            }
        }