Example #1
0
 void Locator_PositionChanged(object sender, Plugin.Geolocator.Abstractions.PositionEventArgs e)
 {
     locationsMap.MoveToRegion(new Xamarin.Forms.Maps.MapSpan(
                                   new Xamarin.Forms.Maps.Position(e.Position.Latitude, e.Position.Longitude),
                                   2,
                                   2));
 }
Example #2
0
 private void Locator_PositionChanged(object sender, Plugin.Geolocator.Abstractions.PositionEventArgs e)
 {
     Analytics.TrackEvent("Position changed");
     Debug.WriteLine($"Position changed: {e.Position.Latitude.ToString()}, {e.Position.Longitude.ToString()}");
     lblPositionLatitude.Text  = e.Position.Latitude.ToString();
     lblPositionLongitude.Text = e.Position.Longitude.ToString();
 }
        private void Locator_PositionChanged(object sender, Plugin.Geolocator.Abstractions.PositionEventArgs e)
        {
            var center = new Xamarin.Forms.Maps.Position(e.Position.Latitude, e.Position.Longitude);
            var span   = new Xamarin.Forms.Maps.MapSpan(center, 2, 2);

            locationsMap.MoveToRegion(span);
        }
Example #4
0
 private void Current_PositionChanged(object sender, Plugin.Geolocator.Abstractions.PositionEventArgs e)
 {
     Device.BeginInvokeOnMainThread(async() =>
     {
         await GetCurrentLocation(e.Position);
     });
 }
        void CrossGeolocator_Current_PositionChanged(object sender, Plugin.Geolocator.Abstractions.PositionEventArgs e)
        {
            var position = e.Position;

            lbllocation.Text = string.Format("Time: {0} \nLat: {1} \nLong: {2} \nAltitude: "
                                             + "{3} \nAltitude Accuracy: {4} \nAccuracy: {5} \nHeading: {6} \nSpeed: {7}",
                                             position.Timestamp, position.Latitude, position.Longitude,
                                             position.Altitude, position.AltitudeAccuracy, position.Accuracy, position.Heading, position.Speed);
        }
Example #6
0
        /// <summary>
        /// React to an update in the GPS position
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void Locator_PositionChanged(object sender, Plugin.Geolocator.Abstractions.PositionEventArgs e)
        {
            Device.BeginInvokeOnMainThread(() =>
            {
                try
                {
                    if (e.Position.Accuracy < 10000)
                    {
                        Preferences.Set("LastPositionLatitude", e.Position.Latitude);
                        Preferences.Set("LastPositionLongitude", e.Position.Longitude);
                        Dictionary <string, double> dic = new Dictionary <string, double>();
                        dic.Add("latitude", e.Position.Latitude);
                        dic.Add("longitude", e.Position.Longitude);
                        Console.WriteLine(e.Position.Latitude.ToString() + ", " + e.Position.Longitude.ToString() + " +/- " + e.Position.Accuracy);
                        dic.Add("accuracy", e.Position.Accuracy);
                        Preferences.Set("LastPositionAccuracy", e.Position.Accuracy);

                        var deviceRotation = 0;

                        switch (DeviceDisplay.MainDisplayInfo.Rotation.ToString())
                        {
                        case "Rotation0":
                            deviceRotation = 0;
                            break;

                        case "Rotation90":
                            deviceRotation = 90;
                            break;

                        case "Rotation180":
                            deviceRotation = 180;
                            break;

                        case "Rotation270":
                            deviceRotation = 270;
                            break;

                        default:
                            break;
                        }

                        var actualHeading = Math.Abs((e.Position.Heading + deviceRotation) % 360);

                        dic.Add("heading", actualHeading);
                        Preferences.Set("LastPositionHeading", e.Position.Heading);
                        dic.Add("speed", e.Position.Speed);
                        Preferences.Set("LastPositionSpeed", e.Position.Speed);
                        MessagingCenter.Send <GPS, Dictionary <string, double> >(this, "GPSPositionUpdate", dic);
                    }
                }
                catch (Exception ex)
                {
                    Console.WriteLine(ex);
                }
            });
        }
Example #7
0
        private void Current_PositionChanged(object sender, Plugin.Geolocator.Abstractions.PositionEventArgs e)
        {
            Device.BeginInvokeOnMainThread(() =>
            {
                var test = e.Position;

                if (gpsStatus == null)
                {
                    gpsStatus = new GPSStatus
                    {
                        lat       = test.Latitude,
                        lng       = test.Longitude,
                        speed     = Convert.ToInt32(test.Speed),
                        timestamp = test.Timestamp.ToLocalTime().ToString(),
                    };
                }
                else
                {
                    gpsStatus.update(test.Latitude, test.Longitude, Convert.ToInt32(test.Speed), test.Timestamp.ToLocalTime().ToString());
                }


                eTrackDatabase.SaveItem(new ETrackItem
                {
                    car_id        = "",
                    user_id       = 26,
                    gps_latitude  = gpsStatus.lat,
                    gps_longitude = gpsStatus.lng,
                    mileage       = gpsStatus.mileage,
                    vehicle_speed = gpsStatus.speed,
                    dt            = (long)(DateTime.UtcNow.Subtract(new DateTime(1970, 1, 1))).TotalMilliseconds,
                });
                numberOfETrackItems++;
                writeMessage.Text = $"{numberOfETrackItems}";

                if (numberOfETrackItems >= 20)
                {
                    ETrackItem[] eTrackItems = eTrackDatabase.GetItems().ToArray();
                    eTrackDatabase.DeleteAll();
                    numberOfETrackItems = 0;
                    Task.Run(() => UploadToS3(eTrackItems));
                }


                listenLabel.Text  = "Full: Lat: " + gpsStatus.lat.ToString() + " Long: " + gpsStatus.lng.ToString();
                listenLabel.Text += "\n" + $"Time: {gpsStatus.timestamp}";
                listenLabel.Text += "\n" + $"Speed: {gpsStatus.speed.ToString()}";
                listenLabel.Text += "\n" + $"Mileage: {gpsStatus.mileage}";

                MoveMark(test.Latitude, test.Longitude);
                //SetCenter(test.Latitude, test.Longitude);
            });
        }
Example #8
0
        private void Current_PositionChanged(object sender, Plugin.Geolocator.Abstractions.PositionEventArgs e)
        {
            if (lastKnowPosition == null || lastKnowPosition.Latitude != e.Position.Latitude || lastKnowPosition.Longitude != e.Position.Longitude)
            {
                lastKnowPosition = e.Position;

                Device.BeginInvokeOnMainThread(() =>
                {
                    MessagingCenter.Send(e.Position, "LocationChanged");
                });
            }
        }
        private void Current_PositionChanged(object sender, Plugin.Geolocator.Abstractions.PositionEventArgs e)
        {
            if (!CrossGeolocator.Current.IsListening)
            {
                return;
            }
            var position = CrossGeolocator.Current.GetPositionAsync();

            lat.Text = position.Result.Latitude.ToString();
            lon.Text = position.Result.Longitude.ToString();
            //Llamar modelview de cercania
        }
        /// <summary>
        /// Called when position has changed
        /// </summary>
        /// <param name="sender">sender object</param>
        /// <param name="args">event args, including position</param>
        private void OnPositionChanged(object sender, Plugin.Geolocator.Abstractions.PositionEventArgs args)
        {
            var position = args.Position;

            bool zoomToPosition = this.zoomToMyPosition;

            this.zoomToMyPosition = false;

            if (this.mapView != null)
            {
                this.mapView.UpdateMyLocation(
                    new MapPoint(position.Latitude, position.Longitude), zoomToPosition);
            }
        }
 private void Current_PositionChanged(object sender, Plugin.Geolocator.Abstractions.PositionEventArgs e)
 {
     this.RunOnUiThread(() =>
     {
         var test = e.Position;
         Console.WriteLine("Value: {0} {1}", test.Latitude, test.Longitude);
         //listenLabel.Text = "Full: Lat: " + test.Latitude.ToString() + " Long: " + test.Longitude.ToString();
         //listenLabel.Text += "\n" + $"Time: {test.Timestamp.ToString()}";
         //listenLabel.Text += "\n" + $"Heading: {test.Heading.ToString()}";
         //listenLabel.Text += "\n" + $"Speed: {test.Speed.ToString()}";
         //listenLabel.Text += "\n" + $"Accuracy: {test.Accuracy.ToString()}";
         //listenLabel.Text += "\n" + $"Altitude: {test.Altitude.ToString()}";
         //listenLabel.Text += "\n" + $"AltitudeAccuracy: {test.AltitudeAccuracy.ToString()}";
     });
 }
Example #12
0
        void Current_PositionChanged(object sender, Plugin.Geolocator.Abstractions.PositionEventArgs e)
        {
            LocationReceived(e.Position);



            //String aText = null;
            //var test = e.Position;
            //aText = "Full: Lat: " + test.Latitude.ToString() + " Long: " + test.Longitude.ToString();
            //aText += "\n" + $"Time: {test.Timestamp.ToString()}";
            //aText += "\n" + $"Heading: {test.Heading.ToString()}";
            //aText += "\n" + $"Speed: {test.Speed.ToString()}";
            //aText += "\n" + $"Accuracy: {test.Accuracy.ToString()}";
            //aText += "\n" + $"Altitude: {test.Altitude.ToString()}";
            //aText += "\n" + $"AltitudeAccuracy: {test.AltitudeAccuracy.ToString()}";

            //Console.WriteLine(aText);
        }
Example #13
0
 void Locator_PositionChanged(object sender, Plugin.Geolocator.Abstractions.PositionEventArgs e)
 {
     Console.WriteLine(e.Position.Latitude.ToString() + "   " + e.Position.Longitude.ToString());
     try {
         using (var db = new SQLite.SQLiteConnection(DATABASE_PATH)) {
             GeoLocation geo = new GeoLocation();
             geo.Date       = DateTime.Now;
             geo.BranchCode = BRANCH_CODE;
             geo.CompCode   = COMPANY_CODE;
             geo.UserID     = USERID_CODE;
             geo.lat        = e.Position.Latitude;
             geo.lng        = e.Position.Longitude;
             geo.Altitude   = e.Position.Altitude;
             geo.Heading    = e.Position.Heading;
             db.Insert(geo);
         }
     } catch {
     }
 }
Example #14
0
        /// <summary>
        /// Called when position has changed
        /// </summary>
        /// <param name="sender">sender object</param>
        /// <param name="args">event args, including position</param>
        private void OnPositionChanged(object sender, Plugin.Geolocator.Abstractions.PositionEventArgs args)
        {
            var position = args.Position;

            bool zoomToPosition = this.zoomToMyPosition;

            this.zoomToMyPosition = false;

            var point = new MapPoint(position.Latitude, position.Longitude, position.Altitude);

            if (this.mapView != null)
            {
                this.mapView.UpdateMyLocation(
                    point,
                    (int)position.Accuracy,
                    position.Speed * Geo.Spatial.Constants.FactorMeterPerSecondToKilometerPerHour,
                    position.Timestamp,
                    zoomToPosition);
            }

            Task.Run(async() => await this.UpdateLastShownPositionAsync(point));
        }
Example #15
0
        /*Handle the position change event*/
        private async void PositionChanged(object sender, Geolocator.PositionEventArgs e)
        {
            await Task.Run(async() =>
            {
                var CurrentPosition = e.Position; //Used to store all the users current positions data
                var Distance        = 6371 * Math.Acos(Math.Cos(ConvertToRadians(CurrentPosition.Latitude)) * Math.Cos(ConvertToRadians(DBPosition.Latitude)) * Math.Cos(ConvertToRadians(DBPosition.Longitude) - ConvertToRadians(CurrentPosition.Longitude)) + Math.Sin(ConvertToRadians(CurrentPosition.Latitude)) * Math.Sin(ConvertToRadians(DBPosition.Latitude)));

                //If-statement to check if the distance between current user position and the position last time the database has been accessed is greater than or equal to 1 Km
                if (Distance >= 1)
                {
                    DBPosition = LastPosition = CurrentPosition;
                    await GetPlaces(); //Calls the function to get all the places nearby
                }
                else if ((CurrentPosition.Latitude != LastPosition.Latitude) || (CurrentPosition.Longitude != LastPosition.Longitude))
                {
                    await CalculateDistance(CurrentPosition); //Calls the function to re-calculate the distance between the user and each place in the list
                    LastPosition = CurrentPosition;
                }

                UpdateUserLocation(CurrentPosition); //Calls the function to update the user it's position on the map
            });
        }
Example #16
0
        private void updateRouteMeasuring(object sender, Plugin.Geolocator.Abstractions.PositionEventArgs e)
        {
            var currLocation = e.Position;

            if (lastKnownLocation == null)
            {
                lastKnownLocation = currLocation;
            }

            var distance = Location.CalculateDistance(lastKnownLocation.Latitude, lastKnownLocation.Longitude, currLocation.Latitude, currLocation.Longitude, DistanceUnits.Kilometers);

            if (distance != 0)
            {
                distanceOfCoordsSum += distance;
                DistanceInKM         = distanceOfCoordsSum;
                Speed = currLocation.Speed;
                locationsList.Add(currLocation);
                SpeedQueue.Enqueue(currLocation.Speed);

                lastKnownLocation = currLocation;
            }
        }
Example #17
0
 private void Locator_PositionChanged(object sender, Plugin.Geolocator.Abstractions.PositionEventArgs e)
 {
     Movemap(e.Position);
 }
Example #18
0
 //update location of user
 async private void OnPositionChanged(object sender, PositionEventArgs e)
 {
     var locator = CrossGeolocator.Current;
     var position = await locator.GetPositionAsync(timeoutMilliseconds: 10000);
     var latitude = position.Latitude.ToString();
     var longtitude = position.Longitude.ToString();
 }
Example #19
0
        private void Locator_PositionChanged(object sender, Plugin.Geolocator.Abstractions.PositionEventArgs e)
        {
            ViewModel.UpdateWorldLocation(e.Position.Latitude, e.Position.Longitude);

            Button.SetTitle($"{e.Position.Latitude} {e.Position.Longitude}", UIControlState.Normal);
        }
 private void OnPositionChanged(PositionEventArgs e)
 {
     var handler = PositionChanged;
     if (handler != null)
         handler(this, e);
 }
 private void Current_PositionChanged(object sender, Plugin.Geolocator.Abstractions.PositionEventArgs e)
 {
     CurrentPosition = e.Position;
 }
        /// <inheritdoc/>
        private void OnListenerPositionChanged(object sender, PositionEventArgs e)
        {
            if (!IsListening) // ignore anything that might come in afterwards
                return;

            lock (positionSync)
            {
                lastPosition = e.Position;

                var changed = PositionChanged;
                if (changed != null)
                    changed(this, e);
            }
        }
Example #23
0
 //update location
 async private void OnPositionChanged(object sender, PositionEventArgs e)
 {
     var locator = CrossGeolocator.Current;
     var position = await locator.GetPositionAsync(timeoutMilliseconds: 10000);
     var latitude = position.Latitude.ToString();
     var longtitude = position.Longitude.ToString();
     //label2.Text = String.Format("Longitude: {0} Latitude: {1}", longtitude, latitude);
 }
 private void CrossGeolocator_PositionChanged(object sender, Plugin.Geolocator.Abstractions.PositionEventArgs e)
 {
     OnPositionChanged(e.Position.ToGeolocation());
 }
Example #25
0
 private async void Current_PositionChanged(object sender, Plugin.Geolocator.Abstractions.PositionEventArgs e)
 {
     Debug.WriteLine($"LocationChangeEvent occured: lat={e.Position.Latitude}; long={e.Position.Longitude}");
     await proximityService.CheckProximityAsync(e.Position.Latitude, e.Position.Longitude);
 }
Example #26
0
        // auto-complete-added event handler method in the event of a change in the user's,location
        private void Locator_PositionChanged(object sender, Plugin.Geolocator.Abstractions.PositionEventArgs e)
        {
            // throw new NotImplementedException();     // boilerplate

            MoveMap(e.Position);             // auto-completed signature parameter for event handler will already contain position arguments
        }
		private void OnPositionChanged (PositionEventArgs e)
		{
			var changed = PositionChanged;
			if (changed != null)
				changed (this, e);
		}
Example #28
0
 private void Locator_PositionChanged(object sender, Plugin.Geolocator.Abstractions.PositionEventArgs e)
 {
     CenterMap(e.Position.Latitude, e.Position.Longitude);
 }
Example #29
0
 private async void Locator_PositionChanged(object sender, Plugin.Geolocator.Abstractions.PositionEventArgs e)
 {
     await MoveMapToRegion(e.Position);
 }
        async void Geolocator_PositionChanged(object sender, PositionEventArgs e)
        {
            // Only update the route if we are meant to be recording coordinates
            if (IsRecording)
            {
                var userLocation = e.Position;

                TripPoint previous = null;
                double newDistance = 0;
                if (CurrentTrip.Points.Count > 1)
                {
                    previous = CurrentTrip.Points[CurrentTrip.Points.Count - 1];
                    newDistance = DistanceUtils.CalculateDistance(userLocation.Latitude,
                        userLocation.Longitude, previous.Latitude, previous.Longitude);

                    if (newDistance > 4) // if more than 4 miles then gps is off don't use
                        return;
                }

                var point = new TripPoint
                    {
                        TripId = CurrentTrip.Id,
                        RecordedTimeStamp = DateTime.UtcNow,
                        Latitude = userLocation.Latitude,
                        Longitude = userLocation.Longitude,
                        Sequence = CurrentTrip.Points.Count,
                        Speed = -255,
                        RPM = -255,
                        ShortTermFuelBank = -255,
                        LongTermFuelBank = -255,
                        ThrottlePosition = -255,
                        RelativeThrottlePosition = -255,
                        Runtime = -255,
                        DistanceWithMalfunctionLight = -255,
                        EngineLoad = -255,
                        MassFlowRate = -255,
                        EngineFuelRate = -255,
                        VIN = "-255"
                    };
       
                //Add OBD data
                if (obdDataProcessor != null)
                    point.HasSimulatedOBDData = obdDataProcessor.IsObdDeviceSimulated;
                await AddOBDDataToPoint(point);

                CurrentTrip.Points.Add(point);

                try
                {
                    if (obdDataProcessor != null)
                    {
                        //Push the trip data packaged with the OBD data to the IOT Hub
                        obdDataProcessor.SendTripPointToIOTHub(CurrentTrip.Id, CurrentTrip.UserId, point);
                    }
                }
                catch (Exception ex)
                {
                    Logger.Instance.Report(ex);
                }

                if (CurrentTrip.Points.Count > 1 && previous != null)
                {
                    CurrentTrip.Distance += newDistance;
                    Distance = CurrentTrip.TotalDistanceNoUnits;

                    //calculate gas usage
                    var timeDif1 = point.RecordedTimeStamp - previous.RecordedTimeStamp;
                    CurrentTrip.FuelUsed += fuelConsumptionRate * 0.00002236413 * timeDif1.TotalSeconds;
                    if (CurrentTrip.FuelUsed == 0)
                        FuelConsumption = "N/A";
                    else
                        FuelConsumption = Settings.MetricUnits
                            ? (CurrentTrip.FuelUsed * 3.7854).ToString("N2")
                            : CurrentTrip.FuelUsed.ToString("N2");
                }
                else
                {
                    CurrentTrip.FuelUsed = 0;
                    FuelConsumption = "N/A";
                }

                var timeDif = point.RecordedTimeStamp - CurrentTrip.RecordedTimeStamp;

                //track seconds, minutes, then hours
                if (timeDif.TotalMinutes < 1)
                    ElapsedTime = $"{timeDif.Seconds}s";
                else if (timeDif.TotalHours < 1)
                    ElapsedTime = $"{timeDif.Minutes}m {timeDif.Seconds}s";
                else
                    ElapsedTime = $"{(int)timeDif.TotalHours}h {timeDif.Minutes}m {timeDif.Seconds}s";

                if (point.EngineLoad != -255)
                    EngineLoad = $"{(int)point.EngineLoad}%";

                FuelConsumptionUnits = Settings.MetricUnits ? "Liters" : "Gallons";
                DistanceUnits = Settings.MetricDistance ? "Kilometers" : "Miles";

                OnPropertyChanged("Stats");
            }

            CurrentPosition = e.Position;
        }
 void OnPositionChanged(PositionEventArgs e) => PositionChanged?.Invoke(this, e);