private void Provider_SearchCompleted(object sender, SearchCompletedEventArgs args)
        {
            this.itemCollection.Clear();
            SearchResultCollection results = args.Response.ResultSets.First().Results;
            if (results.Count > 0)
            {
                foreach (SearchResultBase result in results)
                {
                    MapItem item = new MapItem()
                    {
                        Title = result.Name,
                        Location = result.LocationData.Locations[0]
                    };
                    this.itemCollection.Add(item);
                }
                this.radMap.SetView(args.Response.ResultSets[0].SearchRegion.GeocodeLocation.BestView);
            }

            this.itemCollection.Clear();

            SearchResponse response = args.Response;
            if (response != null)
            {
                if (response.Error == null)
                {
                    if (response.ResultSets.Count > 0)
                    {
                        this.AddResultsToItemsCollection(response);

                        if (response.ResultSets[0].SearchRegion != null)
                        {
                            // Set map viewport to the best view returned in the search result.
                            this.SetBestView(response);

                            // Show map shape around bounding area
                            this.ShowBoundingArea(response);

                            this.SearchRegionToItemsCollection(response);
                        }
                    }
                }
                else
                {
                    // Show error info.
                    MessageBox.Show(
                        response.Error.ToString(),
                        "Error",
                        MessageBoxButton.OK,
                        MessageBoxImage.Error);
                }
            }
        }
 private void AddResultsToItemsCollection(SearchResponse response)
 {
     if (response.ResultSets[0].Results.Count > 0)
     {
         foreach (SearchResultBase result in response.ResultSets[0].Results)
         {
             MapItem item = new MapItem()
             {
                 Title = result.Name,
                 Location = result.LocationData.Locations[0]
             };
             this.itemCollection.Add(item);
         }
     }
 }
 private void SearchRegionToItemsCollection(SearchResponse response)
 {
     if (response.ResultSets[0].SearchRegion.GeocodeLocation != null
         && response.ResultSets[0].SearchRegion.GeocodeLocation.Address != null
         && response.ResultSets[0].SearchRegion.GeocodeLocation.Locations.Count > 0)
     {
         foreach (Location location in response.ResultSets[0].SearchRegion.GeocodeLocation.Locations)
         {
             MapItem item = new MapItem()
             {
                 Title = response.ResultSets[0].SearchRegion.GeocodeLocation.Address.FormattedAddress,
                 Location = location
             };
             this.itemCollection.Add(item);
         }
     }
 }
Example #4
0
        private void searchProvider_SearchCompleted(object sender, SearchCompletedEventArgs e)
        {
            this.informationLayer.Items.Clear();

            SearchResultCollection results = e.Response.ResultSets.First().Results;

            if (results.Count > 0)
            {
                foreach (SearchResultBase result in results)
                {
                    MapItem item = new MapItem();
                    item.Caption = result.Name;
                    item.Location = result.LocationData.Locations.First();
                    item.BaseZoomLevel = 9;
                    item.ZoomRange = new ZoomRange(5, 12);
                    this.informationLayer.Items.Add(item);
                }
            }
            else
            {
                SearchRegion region = e.Response.ResultSets.First().SearchRegion;

                if (region != null)
                {
                    this.radMap.SetView(region.GeocodeLocation.BestView);

                    if (region.GeocodeLocation.Address != null && region.GeocodeLocation.Locations.Count > 0)
                    {
                        foreach (Location location in region.GeocodeLocation.Locations)
                        {
                            MapItem item = new MapItem();
                            item.Caption = region.GeocodeLocation.Address.FormattedAddress;
                            item.Location = location;
                            item.BaseZoomLevel = 5;
                            item.ZoomRange = new ZoomRange(5, 12);
                            this.informationLayer.Items.Add(item);
                        }
                    }
                }
            }

            SearchRegionCollection alternateRegions = e.Response.ResultSets.First().AlternateSearchRegions;

            if (alternateRegions.Count > 0)
            {
                foreach (SearchRegion region in alternateRegions)
                {
                    if (region.GeocodeLocation.Address != null && region.GeocodeLocation.Locations.Count > 0)
                    {
                        foreach (Location location in region.GeocodeLocation.Locations)
                        {
                            MapItem item = new MapItem();
                            item.Caption = region.GeocodeLocation.Address.FormattedAddress;
                            item.Location = location;
                            item.BaseZoomLevel = 5;
                            item.ZoomRange = new ZoomRange(5, 12);
                            this.SuggestionsListBox.Items.Add(item);
                        }
                    }
                }
            }
        }