GeocodeServiceClient.ReverseGeocode Method

 

Finds geographic entities and addresses for a specified map location (known as reverse geocoding).

Syntax

public GeocodeResponse ReverseGeocode(ReverseGeocodeRequest request)
Public Function ReverseGeocode(ByVal request As ReverseGeocodeRequest) As GeocodeResponse

Parameters

request

A ReverseGeocodeRequest object that contains the header and parameter information for the service operation.

Return Value

Returns a GeocodeResponse Class, which contains a GeocodeResult Class array.

Example

private void MakeReverseGeocodeRequest() {
    string Results = "";
    try {
        //  Set a Bing Maps key before making a request 
        string key = "Bing Maps Key";
        GeocodeService.ReverseGeocodeRequest reverseGeocodeRequest = new GeocodeService.ReverseGeocodeRequest();
        //  Set the credentials using a valid Bing Maps key 
        reverseGeocodeRequest.Credentials = new GeocodeService.Credentials();
        reverseGeocodeRequest.Credentials.ApplicationId = key;
        //  Set the point to use to find a matching address 
        GeocodeService.Location point = new GeocodeService.Location();
        point.Latitude = 47.608;
        point.Longitude = -122.337;
        reverseGeocodeRequest.Location = point;
        //  Make the reverse geocode request 
        GeocodeService.GeocodeServiceClient geocodeService = new GeocodeService.GeocodeServiceClient("BasicHttpBinding_IGeocodeService");
        GeocodeService.GeocodeResponse geocodeResponse = geocodeService.ReverseGeocode(reverseGeocodeRequest);
        Results = geocodeResponse.Results[0].DisplayName;
    } catch (Exception ex) {
        Results = "An exception occurred: " + ex.Message;
    }
}
Private Sub MakeReverseGeocodeRequest() Dim Results As String 
    Try
'  Set a Bing Maps key before making a request 
    Dim key = "Bing Maps Key" Dim reverseGeocodeRequest As New GeocodeService.ReverseGeocodeRequest()
'  Set the credentials using a valid Bing Maps key 
    reverseGeocodeRequest.Credentials = _ New GeocodeService.Credentials() With {
    .ApplicationId = key
    }
'  Set the point to use to find a matching address 
    Dim point As New GeocodeService.Location() With {
    .Latitude = 47.608, .Longitude = -122.337
    } reverseGeocodeRequest.Location = point
'  Make the reverse geocode request 
    Dim GeocodeServiceInstance As New GeocodeService.GeocodeServiceClient("BasicHttpBinding_IGeocodeService") 
    Dim geocodeResponse = GeocodeServiceInstance.ReverseGeocode(reverseGeocodeRequest) 
    Results = geocodeResponse.Results(0).DisplayName 
    Catch ex As Exception Results = "An exception occurred: " & ex.Message 
    End Try 
End Sub

See Also

GeocodeServiceClient.Geocode Method