// Create a simple handler for the SpeechRecognized event.
 void sr_SpeechRecognized(object sender, SpeechRecognizedEventArgs e)
 {
     MessageBox.Show(e.Result.Text );
     var request = new GeocodingRequest();
     request.Address = e.Result.Text;
     request.Sensor = "false";
     var response = GeocodingService.GetResponse(request);
     if (response.Status == ServiceResponseStatus.Ok)
     {
         currentSelectedLocation = response.Results.First();
     }
     updateMap();
     //================
     //var result = (GeocodingResult)currentSelectedLocation;
     //fullAddress.Text = result.FormattedAddress;
     //var location = result.Geometry.Location;
     //var map = new StaticMap();
     //map.Center = location.Latitude.ToString() + "," + location.Longitude.ToString();
     //txtLatitude.Text = location.Latitude.ToString();
     //txtLongitude.Text = location.Longitude.ToString();
     //map.Zoom =
     //(zoomLevels.SelectedItem == null) ? "10" : zoomLevels.Text.ToString();
     //map.Markers = map.Center;
     //map.Size = "1000" + "x" + "485";
     //map.MapType =
     //(mapTypeCombo.SelectedItem == null) ? "roadmap" : mapTypeCombo.Text.ToString();
     //map.Sensor = "false";
     //String urlToMap = map.ToUri().AbsoluteUri.ToString();
     //mapViewer.Navigate(urlToMap);
 }
 private void button1btnSearch_Click(object sender, EventArgs e)
 {
     var request = new GeocodingRequest();
     request.Address = txtLocation.Text;
     request.Sensor = "false";
     var response = GeocodingService.GetResponse(request);
     if (response.Status == ServiceResponseStatus.Ok)
     {
         currentSelectedLocation = response.Results.First();
     }
     updateMap();
 }
Exemple #3
0
        public Uri GenerateStaticMapUrl(GeocodingResult searchResult)
        {
            var map = new StaticMap();
            map.Center = searchResult.FormattedAddress; // or a lat/lng coordinate
            //map.Path = searchResult.FormattedAddress + "|" + "9 Snowball Place Wanniassa";
            map.Zoom = "14";
            map.Size = "400x400";
            map.Sensor = "true";
            map.Markers = searchResult.FormattedAddress;
            Uri url = map.ToUri();

            return url;
        }
        /// <summary>
        /// Converts a Geocode response to a tree
        /// </summary>
        /// <param name="results"></param>
        /// <returns></returns>
        public static TreeViewItem[] ToTree(GeocodingResult[] results)
        {
            var nodes = new List<TreeViewItem>();

            foreach (var result in results)
            {
                var node = new TreeViewItem();
                node.Header = "(" + result.Types.FirstOrDefault() + ") " + result.FormattedAddress;
                node.Tag = new SelectedObject(result.Types.FirstOrDefault(), result.Geometry.Location);

                foreach (var component in result.Components)
                {
                    node.Items.Add(new TreeViewItem
                    {
                        Header = component.Types.FirstOrDefault() + ": " + component.LongName,
                        Tag = result.Geometry.Location
                    });
                }

                node.Items.Add(new TreeViewItem { Header = "Lat: " + result.Geometry.Location.Latitude });
                node.Items.Add(new TreeViewItem { Header = "Lng: " + result.Geometry.Location.Longitude });

                nodes.Add(node);
            }

            return nodes.ToArray();
        }
        private void txtLocation_TextChanged(object sender, EventArgs e)
        {
            String str = txtLocation.Text;
            String[] input =str.Split(new char[' ']);
            try
            {
                if (input[input.Length - 1] == "search")
                {
                    var request = new GeocodingRequest();
                    request.Address = txtLocation.Text;
                    request.Sensor = "false";
                    var response = GeocodingService.GetResponse(request);
                    if (response.Status == ServiceResponseStatus.Ok)
                    {
                        currentSelectedLocation = response.Results.First();
                    }

                    updateMap();
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine("exception caught");
            }
        }