示例#1
0
        /// <summary>
        /// Updates list of known places
        /// </summary>
        /// <returns>Asynchronous task</returns>
        private async Task UpdateKnownPlacesAsync()
        {
            if (_monitor != null)
            {
                _app.Places = null;

                PlacesMap.MapElements.Clear();

                if (await CallSensorcoreApiAsync(async() => { _app.Places = await _monitor.GetKnownPlacesAsync(); }))
                {
                    foreach (var p in _app.Places)
                    {
                        System.Diagnostics.Debug.WriteLine("Place {0} radius {1} Latitude {2} Longitude {3} ", p.Kind, p.Radius, p.Position.Latitude, p.Position.Longitude);
                        var icon = new MapIcon();
                        MapExtensions.SetValue(icon, p);

                        icon.NormalizedAnchorPoint = new Windows.Foundation.Point(0.5, 1);
                        icon.Location = new Geopoint(p.Position);
                        icon.Title    = p.Kind.ToString();
                        Color color;

                        switch (p.Kind)
                        {
                        case PlaceKind.Home:
                            color = PlacesColorHome;
                            break;

                        case PlaceKind.Work:
                            color = PlacesColorWork;
                            break;

                        case PlaceKind.Frequent:
                            color = PlacesColorFrequent;
                            break;

                        case PlaceKind.Known:
                            color = PlacesColorKnown;
                            break;

                        default:
                            color = PlacesColorUnknown;
                            break;
                        }

                        PlacesMap.MapElements.Add(icon);
                        CreateGeofence(p.Id.ToString(), p.Position.Latitude, p.Position.Longitude, p.Radius, color);
                    }
                }
            }
            Debug.WriteLine("Known places updated.");
        }
示例#2
0
        /// <summary>
        /// Creates map icon for track point
        /// </summary>
        /// <param name="point">Track point to create map icon for</param>
        /// <param name="largeIcon">If <c>true</c> will use large icon, if <c>false</c> will use small icon</param>
        private void CreateMapIcon(TrackPoint point, bool largeIcon)
        {
            var icon = new MapIcon
            {
                NormalizedAnchorPoint = new Windows.Foundation.Point(0.5, 0.5),
                Location = new Geopoint(point.Position)
            };

            if (largeIcon)
            {
                icon.Image = RandomAccessStreamReference.CreateFromUri(new Uri("ms-appx:///Assets/dot.png"));
            }
            else
            {
                icon.Image = RandomAccessStreamReference.CreateFromUri(new Uri("ms-appx:///Assets/dotSmall.png"));
            }
            MapExtensions.SetValue(icon, point);
            TracksMap.MapElements.Add(icon);
        }
示例#3
0
        /// <summary>
        /// Updates list of known places
        /// </summary>
        /// <param name="date">Date to search places from. Use <c>null</c> to search entire history.</param>
        /// <returns>Asynchronous task</returns>
        private async Task UpdateKnownPlacesAsync(DateTime?date)
        {
            if (_placeMonitor != null)
            {
                _app.Places = null;
                PlacesMap.MapElements.Clear();
                PlacesMap.Children.Clear();
                if (await CallSensorcoreApiAsync(async() =>
                {
                    if (date.HasValue)
                    {
                        _app.Places = await _placeMonitor.GetPlaceHistoryAsync(date.Value.Date, TimeSpan.FromHours(24));
                    }
                    else
                    {
                        _app.Places = await _placeMonitor.GetKnownPlacesAsync();
                    }
                }))
                {
                    // Make sure that there were Places for the timespan
                    if (_app.Places != null &&
                        _app.Places.Count > 0)
                    {
                        PlacesMap.Children.Clear();

                        foreach (var p in _app.Places)
                        {
                            System.Diagnostics.Debug.WriteLine("Place {0} radius {1} Latitude {2} Longitude {3} Total visit count {4} Total length of stay {5} Length of stay {6} Kind {7} ", p.Kind, p.Radius, p.Position.Latitude, p.Position.Longitude, p.TotalVisitCount, p.TotalLengthOfStay, p.LengthOfStay, p.Kind);
                            var mapIcon = new MapIcon();
                            MapExtensions.SetValue(mapIcon, p);
                            mapIcon.NormalizedAnchorPoint = new Windows.Foundation.Point(0.5, 0.5);
                            mapIcon.Location = new Geopoint(p.Position);
                            mapIcon.Title    = "'" + p.Kind.ToString() + "'" + " place";
                            Color placesColor;
                            //Set for each type of a place a certain color and set custom image for the MapIcon
                            switch (p.Kind)
                            {
                            case PlaceKind.Home:
                                placesColor = PLACE_COLOR_HOME;
                                break;

                            case PlaceKind.Work:
                                placesColor = PLACE_COLOR_WORK;
                                break;

                            case PlaceKind.Frequent:
                                placesColor = PLACE_COLOR_FREQUENT;
                                break;

                            case PlaceKind.Known:
                                placesColor = PLACE_COLOR_KNOWN;
                                break;

                            default:
                                placesColor = PLACE_COLOR_UNKNOWN;
                                break;
                            }
                            PlacesMap.MapElements.Add(mapIcon);
                            CreateGeofence(p.Id.ToString(), p.Position.Latitude, p.Position.Longitude, p.Radius, placesColor);
                        }
                    }
                }
            }
            Debug.WriteLine("Known places updated.");
        }