none
Trying to get accurate Address results with Bing Maps SDK

    Question

  • So here is the main goal. Have a search box that a user can type into and the results will show up in a listbox below it.

    I have a textbox that has a "TextChanged" Event. When the text changes, I want the results from the search to populate a listbox.

    Xaml

    <TextBox x:Name="GeocodeTbx" Height="25" TextChanged="GeocodeTbx_TextChanged" /> <ListBox x:Name="GeocodeResults" Margin="0,10,0,0" Visibility="Collapsed">

    C#

    private void GeocodeResultSelected(object sender, SelectionChangedEventArgs e)
            {
                var listBox = sender as ListBox;
    
                if (listBox.SelectedItems.Count > 0)
                {
                    //Get the Selected Item
                    var item = listBox.Items[listBox.SelectedIndex] as BingMapsRESTService.Common.JSON.Location;
    
                    //Get the items location
                    Bing.Maps.Location location = new Bing.Maps.Location(item.Point.Coordinates[0], item.Point.Coordinates[1]);               
    
                    //Zoom into the location
                    myMap.SetView(location, 14);
                }
            }      
    
    
            //This is the code Used for the Ticker tape styled list box
            private async void GeocodeTbx_TextChanged(object sender, TextChangedEventArgs e)
            {
                string query = GeocodeTbx.Text;
                GeocodeResults.Visibility = Visibility.Visible;
    
                if (!string.IsNullOrWhiteSpace(query))
                {
                    //Create the request URL for the Geocoding service
                    Uri geocodeRequest = new Uri(string.Format("http://dev.virtualearth.net/REST/v1/Locations?q={0}&key={1}", query, myMap.Credentials));
    
                    //Make a request and get the response
                    Response r = await GetResponse(geocodeRequest);
    
                    if (r != null &&
                        r.ResourceSets != null &&
                        r.ResourceSets.Length > 0 &&
                        r.ResourceSets[0].Resources != null &&
                        r.ResourceSets[0].Resources.Length > 0)
                    {
                        LocationCollection locations = new LocationCollection();
                        int i = 1;
    
                        foreach (BingMapsRESTService.Common.JSON.Location l in r.ResourceSets[0].Resources)
                        {
                            //Get the location of each result
                            Bing.Maps.Location location = new Bing.Maps.Location(l.Point.Coordinates[0], l.Point.Coordinates[1]);
    
                            i++;
    
                            locations.Add(location);
                        }
    
                        GeocodeResults.ItemsSource = r.ResourceSets[0].Resources;
                    }
    
                    else
                    {
                        //ShowMessage("No Results found.");
                        return;
                    }
                }
    
                else
                {
                    //ShowMessage("Invalid Geocode Input.");
                    return;
                }
    
            }

    This code works to bring back results, but it isn't very accurate. As I type in the number 8 and wait a moment, it dosen't return anything that starts with 8. When I remove it and try again, it will return one result that has 8 in it. This is just one example. If you just start typing away you can see how inaccurate it is.

    How can I get it to be more accurate.

    Thanks

    Tex



    • Edited by Texeco Wednesday, August 28, 2013 9:54 PM
    Wednesday, August 28, 2013 9:47 PM

Answers

  • You can't expect a reliable result when you pass in garbage into the geocoder. The geocoder uses a lot of different data when geocoding, including the IP address the request it coming from, where the map is centered and a bunch of other things. Autocomplete functionality is not recommended as it generates a large number of transactions. Many people who implement this end up with large bills. To optimize this functionality make sure there is at least a few characters before doing a geocode.

    http://rbrundritt.wordpress.com

    Thursday, August 29, 2013 9:20 AM

All replies

  • You can't expect a reliable result when you pass in garbage into the geocoder. The geocoder uses a lot of different data when geocoding, including the IP address the request it coming from, where the map is centered and a bunch of other things. Autocomplete functionality is not recommended as it generates a large number of transactions. Many people who implement this end up with large bills. To optimize this functionality make sure there is at least a few characters before doing a geocode.

    http://rbrundritt.wordpress.com

    Thursday, August 29, 2013 9:20 AM
  • Thanks I will look at that
    Wednesday, September 04, 2013 4:48 PM