Пример #1
0
        private void search_Button_Click(object sender, RoutedEventArgs e)
        {
            search_result_list.Items.Clear();
            g_query_result.Clear();

            if (search_box.Text.Length <= 0)
            {
                return;
            }

            string requestUrl = @"http://dev.virtualearth.net/REST/v1/Locations/" + search_box.Text.Trim() + "?o=xml&key=" + BingMapKey;

            // Make the request and get the response
            XmlDocument geocodeResponse = GetXmlResponse(requestUrl);

            // Create namespace manager
            XmlNamespaceManager nsmgr = new XmlNamespaceManager(geocodeResponse.NameTable);

            nsmgr.AddNamespace("rest", "http://schemas.microsoft.com/search/local/ws/rest/v1");

            // Get all geocode locations in the response
            XmlNodeList locationElements = geocodeResponse.SelectNodes("//rest:Location", nsmgr);

            if (locationElements.Count <= 0)
            {
                return;
            }

            for (int i = 0; i < locationElements.Count; i++)
            {
                Location loc = new Location();
                loc.Latitude  = Convert.ToDouble(locationElements[i].SelectSingleNode(".//rest:Latitude", nsmgr).InnerText);
                loc.Longitude = Convert.ToDouble(locationElements[i].SelectSingleNode(".//rest:Longitude", nsmgr).InnerText);

                list_item it = new list_item();
                it.loc  = loc;
                it.Name = locationElements[i].SelectSingleNode(".//rest:Name", nsmgr).InnerText;

                g_query_result.Add(it);
                search_result_list.Items.Add(it.Name);
            }

            // get the elevations for these addresses.
            string        elevationUrl = spell_elevation_query_url(g_query_result);
            List <double> alt_list     = get_elevations(elevationUrl);

            for (int i = 0; i < g_query_result.Count; i++)
            {
                g_query_result[i].loc.Altitude = alt_list[i];
            }
        }
Пример #2
0
 private void search_result_list_SelectionChanged(object sender, System.Windows.Controls.SelectionChangedEventArgs e)
 {
     if (g_query_result.Count <= 0 || search_result_list.SelectedIndex < 0)
     {
         return;
     }
     else
     {
         list_item it = g_query_result[search_result_list.SelectedIndex];
         lat.Text = it.loc.Latitude.ToString();
         lon.Text = it.loc.Longitude.ToString();
         alt.Text = it.loc.Altitude.ToString();
     }
 }
Пример #3
0
        // TODO - the majority of this body that handles parsing should be moved to WebServices...
        private void search_Button_Click(object sender, RoutedEventArgs e)
        {
            search_result_list.Items.Clear();
            g_query_result.Clear();

            if (search_box.Text.Length <= 0)
            {
                return;
            }

            // Make the request and get the response
            XmlDocument geocodeResponse = webServices.DoBingLocationSearch(search_box.Text);

            // Create namespace manager
            XmlNamespaceManager nsmgr = new XmlNamespaceManager(geocodeResponse.NameTable);

            nsmgr.AddNamespace("rest", "http://schemas.microsoft.com/search/local/ws/rest/v1");

            // Get all geocode locations in the response
            XmlNodeList locationElements = geocodeResponse.SelectNodes("//rest:Location", nsmgr);

            if (locationElements.Count <= 0)
            {
                return;
            }

            for (int i = 0; i < locationElements.Count; i++)
            {
                Location loc = new Location();
                loc.Latitude  = Convert.ToDouble(locationElements[i].SelectSingleNode(".//rest:Latitude", nsmgr).InnerText);
                loc.Longitude = Convert.ToDouble(locationElements[i].SelectSingleNode(".//rest:Longitude", nsmgr).InnerText);

                list_item it = new list_item();
                it.loc  = loc;
                it.Name = locationElements[i].SelectSingleNode(".//rest:Name", nsmgr).InnerText;

                g_query_result.Add(it);
                search_result_list.Items.Add(it.Name);
            }

            // get the elevations for these addresses.
            List <double> alt_list = webServices.GetElevationsForLocations(g_query_result.Select(item => item.loc));

            for (int i = 0; i < g_query_result.Count; i++)
            {
                g_query_result[i].loc.Altitude = alt_list[i];
            }
        }
Пример #4
0
        private void search_result_list_MouseDoubleClick(object sender, MouseButtonEventArgs e)
        {
            if (g_query_result.Count <= 0 || search_result_list.SelectedIndex < 0)
            {
                return;
            }
            else
            {
                list_item it = g_query_result[search_result_list.SelectedIndex];
                lat.Text = it.loc.Latitude.ToString();
                lon.Text = it.loc.Longitude.ToString();
                alt.Text = it.loc.Altitude.ToString();

                if (navigator.WalkingState != WalkingState.Stopped)
                {
                    System.Windows.Forms.MessageBox.Show("Quit from walking mode first.");
                    return;
                }
                TeleportToLocation(it.loc);
            }
        }