locked
Finding the Name(In the form of string) by passing the Lat/Long as user Input RRS feed

  • Question

  • Hi,

    Can U help me plz..how can i get the Name(string) of Location.If i m passing the Lat/Long(through input).

    Is it case of reverse Geocoding???????

    Saturday, June 16, 2012 2:01 PM

Answers

  • hi....

    here is solution..i got that..

    in .XAML Page

    <!--Reverse Geocoding-->

                        <StackPanel>

                            <TextBlock Text="Latitude" FontSize="12" />
                            <TextBox x:Name="ReverseLatitude" FontSize="11" Width="100" HorizontalAlignment="Left"/>
                            <TextBlock Text="Longitude" FontSize="12" />
                            <TextBox x:Name="ReverseLongitude" FontSize="11"  Width="100" HorizontalAlignment="Left"/>
                            <Button Content="Get Address" Click="btnFindAddress" Width="80" HorizontalAlignment="Right"/>
                            <TextBlock x:Name="OutPutText" Width="Auto" Height="150" />
                        </StackPanel>

    in .XAML.CS Page

      //Reverse geocoding of the address
             Microsoft.Maps.MapControl.Location ReverseLocation;
            private void btnFindAddress(object sender, RoutedEventArgs e)
            {
                ReverseLocation = new Microsoft.Maps.MapControl.Location();
                ReverseLocation.Latitude = Convert.ToDouble(ReverseLatitude.Text);
                ReverseLocation.Longitude = Convert.ToDouble(ReverseLongitude.Text);

                GetAddress(ReverseLocation);

            }

          private void  GetAddress(Microsoft.Maps.MapControl.Location ReverseLocation)
            {
                //create ReverseGeocodeRequest Object
                EDDESWeb.GeocodeService.ReverseGeocodeRequest reverseGeocodeRequest = new EDDESWeb.GeocodeService.ReverseGeocodeRequest();

                // Set the credentials using a valid Bing Maps key
                reverseGeocodeRequest.Credentials = new GeocodeService.Credentials();
                reverseGeocodeRequest.Credentials.ApplicationId = "Bing Maps Key";

                // Set the point to use to find a matching address
                GeocodeService.Location point = new GeocodeService.Location();
                point.Latitude = ReverseLocation.Latitude;
                point.Longitude = ReverseLocation.Longitude;

                reverseGeocodeRequest.Location = point;

                // Make the reverse geocode request
                EDDESWeb.GeocodeService.GeocodeServiceClient geocodeService = new EDDESWeb.GeocodeService.GeocodeServiceClient("BasicHttpBinding_IGeocodeService");
                geocodeService.ReverseGeocodeCompleted += new EventHandler<EDDESWeb.GeocodeService.ReverseGeocodeCompletedEventArgs>(geocodeService_ReverseGeocodeCompleted);
                geocodeService.ReverseGeocodeAsync(reverseGeocodeRequest);

            }

          void geocodeService_ReverseGeocodeCompleted(object sender, EDDESWeb.GeocodeService.ReverseGeocodeCompletedEventArgs e)
          {
              // The result is a GeocodeResponse object
              EDDESWeb.GeocodeService.GeocodeResponse geocodeResponse = e.Result;

              if (geocodeResponse.Results.Count > 0)
                  OutPutText.Text = geocodeResponse.Results[0].DisplayName;
              else
                  OutPutText.Text = "No Results found";
          }

    thnx

    prakas kumar


    • Marked as answer by prakash_light Monday, June 18, 2012 6:03 AM
    • Edited by Ricky_Brundritt Monday, June 18, 2012 8:42 AM Removing Bing Maps key
    Monday, June 18, 2012 6:03 AM

All replies

  • hi....

    here is solution..i got that..

    in .XAML Page

    <!--Reverse Geocoding-->

                        <StackPanel>

                            <TextBlock Text="Latitude" FontSize="12" />
                            <TextBox x:Name="ReverseLatitude" FontSize="11" Width="100" HorizontalAlignment="Left"/>
                            <TextBlock Text="Longitude" FontSize="12" />
                            <TextBox x:Name="ReverseLongitude" FontSize="11"  Width="100" HorizontalAlignment="Left"/>
                            <Button Content="Get Address" Click="btnFindAddress" Width="80" HorizontalAlignment="Right"/>
                            <TextBlock x:Name="OutPutText" Width="Auto" Height="150" />
                        </StackPanel>

    in .XAML.CS Page

      //Reverse geocoding of the address
             Microsoft.Maps.MapControl.Location ReverseLocation;
            private void btnFindAddress(object sender, RoutedEventArgs e)
            {
                ReverseLocation = new Microsoft.Maps.MapControl.Location();
                ReverseLocation.Latitude = Convert.ToDouble(ReverseLatitude.Text);
                ReverseLocation.Longitude = Convert.ToDouble(ReverseLongitude.Text);

                GetAddress(ReverseLocation);

            }

          private void  GetAddress(Microsoft.Maps.MapControl.Location ReverseLocation)
            {
                //create ReverseGeocodeRequest Object
                EDDESWeb.GeocodeService.ReverseGeocodeRequest reverseGeocodeRequest = new EDDESWeb.GeocodeService.ReverseGeocodeRequest();

                // Set the credentials using a valid Bing Maps key
                reverseGeocodeRequest.Credentials = new GeocodeService.Credentials();
                reverseGeocodeRequest.Credentials.ApplicationId = "Bing Maps Key";

                // Set the point to use to find a matching address
                GeocodeService.Location point = new GeocodeService.Location();
                point.Latitude = ReverseLocation.Latitude;
                point.Longitude = ReverseLocation.Longitude;

                reverseGeocodeRequest.Location = point;

                // Make the reverse geocode request
                EDDESWeb.GeocodeService.GeocodeServiceClient geocodeService = new EDDESWeb.GeocodeService.GeocodeServiceClient("BasicHttpBinding_IGeocodeService");
                geocodeService.ReverseGeocodeCompleted += new EventHandler<EDDESWeb.GeocodeService.ReverseGeocodeCompletedEventArgs>(geocodeService_ReverseGeocodeCompleted);
                geocodeService.ReverseGeocodeAsync(reverseGeocodeRequest);

            }

          void geocodeService_ReverseGeocodeCompleted(object sender, EDDESWeb.GeocodeService.ReverseGeocodeCompletedEventArgs e)
          {
              // The result is a GeocodeResponse object
              EDDESWeb.GeocodeService.GeocodeResponse geocodeResponse = e.Result;

              if (geocodeResponse.Results.Count > 0)
                  OutPutText.Text = geocodeResponse.Results[0].DisplayName;
              else
                  OutPutText.Text = "No Results found";
          }

    thnx

    prakas kumar


    • Marked as answer by prakash_light Monday, June 18, 2012 6:03 AM
    • Edited by Ricky_Brundritt Monday, June 18, 2012 8:42 AM Removing Bing Maps key
    Monday, June 18, 2012 6:03 AM
  • I highly recommend using the  Bing Maps REST services instead of the SOAP services. They are faster, newer, have more features and are the recommended service to use going forward. To use the REST services from C# take a look at this article: http://rbrundritt.wordpress.com/2012/01/06/bing-maps-rest-service-net-libraries/

    http://rbrundritt.wordpress.com

    Monday, June 18, 2012 8:44 AM