This example demonstrates how to manually process received Bing Geocode location information.
Important
On May 21, 2024, Microsoft announced that Bing Maps for Enterprise and its API will be discontinued. Azure Maps will be a single unified enterprise mapping platform available from Microsoft.
We are working on API compatible with Azure Maps and expect to ship it with our next major release (v24.2).
If you have an existing license to Bing Maps for Enterprise, you can continue using our existing API. You need to transition to new API until June 30, 2025 (free and basic license) or until June 30, 2028 (enterprise license).
The last date you can get a new license to Bing Maps for Enterprise is June 30, 2025. If you do not have an existing license after that date, you would not be able to use our map controls with Bing Maps or Azure Maps (until we release the new API). During that time, you can use other map providers supported by our controls, such as OpenStreetMap.
Note
If you run the application, and see a window with the following error message: ”The specified Bing Maps key is invalid. To create a developer account, refer to https://www.microsoft.com/en-us/maps/create-a-bing-maps-key”, refer to the following tutorial: How to: Get a Bing Maps Key.
<dxm:BingGeocodeDataProvider x:Name="geocodeProvider" ProcessMouseEvents="False"
BingKey="{Binding Source={StaticResource YourBingKey}}"
LocationInformationReceived="geocodeProvider_LocationInformationReceived"/>
private void geocodeProvider_LocationInformationReceived(object sender, LocationInformationReceivedEventArgs e) {
GeocodeRequestResult result = e.Result;
StringBuilder resultList = new StringBuilder("");
resultList.Append(String.Format("Status: {0}\n", result.ResultCode));
resultList.Append(String.Format("Fault reason: {0}\n", result.FaultReason));
resultList.Append(String.Format("______________________________\n"));
if (result.ResultCode != RequestResultCode.Success) {
tbResults.Text = resultList.ToString();
return;
}
int resCounter = 1;
foreach (LocationInformation locations in result.Locations) {
resultList.Append(String.Format("Request Result {0}:\n", resCounter));
resultList.Append(String.Format("Display Name: {0}\n", locations.DisplayName));
resultList.Append(String.Format("Entity Type: {0}\n", locations.EntityType));
resultList.Append(String.Format("Address: {0}\n", locations.Address));
resultList.Append(String.Format("Location: {0}\n", locations.Location));
resultList.Append(String.Format("______________________________\n"));
resCounter++;
}
tbResults.Text = resultList.ToString();
}
Private Sub geocodeProvider_LocationInformationReceived(ByVal sender As Object, ByVal e As LocationInformationReceivedEventArgs)
Dim result As GeocodeRequestResult = e.Result
Dim resultList As New StringBuilder("")
resultList.Append(String.Format("Status: {0}" & ControlChars.Lf, result.ResultCode))
resultList.Append(String.Format("Fault reason: {0}" & ControlChars.Lf, result.FaultReason))
resultList.Append(String.Format("______________________________" & ControlChars.Lf))
If result.ResultCode <> RequestResultCode.Success Then
tbResults.Text = resultList.ToString()
Return
End If
Dim resCounter As Integer = 1
For Each locations As LocationInformation In result.Locations
resultList.Append(String.Format("Request Result {0}:" & ControlChars.Lf, resCounter))
resultList.Append(String.Format("Display Name: {0}" & ControlChars.Lf, locations.DisplayName))
resultList.Append(String.Format("Entity Type: {0}" & ControlChars.Lf, locations.EntityType))
resultList.Append(String.Format("Address: {0}" & ControlChars.Lf, locations.Address))
resultList.Append(String.Format("Location: {0}" & ControlChars.Lf, locations.Location))
resultList.Append(String.Format("______________________________" & ControlChars.Lf))
resCounter += 1
Next locations
tbResults.Text = resultList.ToString()
End Sub
See Also