Ejemplo n.º 1
0
        public Boolean CanWriteToList(LocationModel model)
        {
            if (ListItemsSource.Count == 0) return true;
            var firstItem = ListItemsSource.First();
            var oldLat = firstItem.coords.latitude;
            var oldLon = firstItem.coords.longitude;
            double oldLatitude;
            double oldLongitude;

            Double.TryParse(oldLat, out oldLatitude);
            Double.TryParse(oldLon, out oldLongitude);

            var newLat = model.coords.latitude;
            var newLon = model.coords.longitude;
            double newLongitude;
            double newLatitude;

            Double.TryParse(newLat, out newLatitude);
            Double.TryParse(newLon, out newLongitude);

            var distance = Math.Sqrt(Math.Pow((newLongitude - oldLongitude), 2) + Math.Pow((newLatitude - oldLatitude), 2)) >= MinLength;
            var timespan = (model.timestamp - firstItem.timestamp) >= MinTime;

            return distance || timespan;
        }
Ejemplo n.º 2
0
        public static LocationModel SetLocationCoordinates(PositionChangedEventArgs args)
        {
            var locationModel = new LocationModel()
            {
                coords = new PositionModel()
            };

            var coordinates = args.Position.Coordinate;
            locationModel.coords.latitude = coordinates.Latitude.ToString();
            locationModel.coords.longitude = coordinates.Longitude.ToString();
            locationModel.coords.altitudeAccuracy = coordinates.AltitudeAccuracy.ToString();
            locationModel.coords.altitude = coordinates.Altitude.ToString();
            locationModel.coords.accuracy = coordinates.Accuracy.ToString();
            locationModel.coords.speed = coordinates.Speed.ToString();
            locationModel.coords.heading = coordinates.Heading.ToString();
            locationModel.timestamp = ToUnixTimestamp(DateTime.Now);

            return locationModel;
        }
Ejemplo n.º 3
0
        public void ReceivePositionCoordinates(LocationModel model)
        {
            Deployment.Current.Dispatcher.BeginInvoke(() =>
            {
                TextMessage = string.Format("{0} {1}", model.coords.latitude, model.coords.longitude);

            });
            var canWrite = CanWriteToList(model);
            if (!canWrite) return;
            ListItemsSource.Add(model);
            SendRequest.SendPositionRequest();
        }