コード例 #1
0
        public static void AddLocationEntry(LocationDescription location)
        {
            if (location == null)
            {
                throw new ArgumentNullException("location");
            }

            if (location.DisplayName.Equals(SR.MyCurrentLocationText, StringComparison.OrdinalIgnoreCase))
            {
                return;
            }

            var matches = _entries.Where(o => o.DisplayName == location.DisplayName);

            var add = true;
            foreach (var m in matches)
            {
                // don't add recurrent search terms
                if (m.GeoCoordinate == null
                    && location.GeoCoordinate == null)
                {
                    add = false;
                    break;
                }

                // Add entry with identical names but different location
                if (m.GeoCoordinate != null
                    && location.GeoCoordinate != null
                    && m.GeoCoordinate.GetDistanceTo(location.GeoCoordinate) < 10)
                {
                    add = false;
                    break;
                }
            }

            if (add)
            {
                // Add an entry with the location set
                _entries.Add(location);
                return;
            }

            // prune excess data
            while (_entries.Count > 200)
            {
                // remove oldest entry, but not My Location
                _entries.RemoveAt(1);
            }
        }
コード例 #2
0
ファイル: MainMapViewModel.cs プロジェクト: kyvok/TransitWP7
        private void UpdateLocation(string endpoint, LocationDescription location)
        {
            DispatcherHelper.CheckBeginInvokeOnUI(
                    () =>
                    {
                        AutoCompleteDataManager.AddLocationEntry(location);

                        if (endpoint == "start")
                        {
                            this.StartLocationText = location.DisplayName;
                            this._isStartLocationStale = false;
                            this.SelectedStartLocation = location;
                        }
                        else
                        {
                            this.EndLocationText = location.DisplayName;
                            this._isEndLocationStale = false;
                            this.SelectedEndLocation = location;
                        }

                        this.CoreCalculateTransit();
                    });
        }
コード例 #3
0
ファイル: MainMapView.xaml.cs プロジェクト: kyvok/TransitWP7
        private void SelectedOnMapActionTap(object sender, System.Windows.Input.GestureEventArgs e)
        {
            var pushpin = (Pushpin)sender;
            var point = e.GetPosition(pushpin);
            var startZone = point.X > 8 && point.X < 72 && point.Y < -16 && point.Y > -42;
            var endZone = point.X < -8 && point.X > -72 && point.Y > 16 && point.Y < 42;
            if (startZone || endZone)
            {
                this.SetUIVisibility(UIViewState.OnlyStartEndInputsView);
                pushpin.Visibility = Visibility.Collapsed;

                this.IsEnabled = false;

                ProxyQuery.GetLocationAddress(
                    pushpin.Location).ContinueWith(
                        continuation =>
                        {
                            var result = continuation.Result.ToList();
                            DispatcherHelper.CheckBeginInvokeOnUI(
                                () =>
                                {
                                    var displayName = "Unknown location";
                                    if (result.Count > 0)
                                    {
                                        displayName = result[0].DisplayName;
                                    }

                                    var loc = new LocationDescription(pushpin.Location) { DisplayName = displayName };
                                    if (startZone)
                                    {
                                        this._viewModel.StartLocationText = displayName;
                                        this._viewModel.SelectedStartLocation = loc;
                                    }
                                    else
                                    {
                                        this._viewModel.EndLocationText = displayName;
                                        this._viewModel.SelectedEndLocation = loc;
                                    }

                                    this.IsEnabled = true;
                                });
                        });
            }

            e.Handled = true;
        }