I’ve had a few requests for a simple example of how to implement the Bing Map web services with the Silverlight control. In particular how to call the Reverse Geocoding services on mouse click. This post will show a straight forward and simple way of doing this. Note that most of the code in this post is derived from the following article: http://msdn.microsoft.com/en-us/library/cc879136.aspx I recommend using this article for simple ways to add the other Bing Map web services.
The following steps will be needed to accomplish this task:
1) Create a Silverlight Application in Visual Studios.
2) Add a service reference to the Geocoding service: http://dev.virtualearth.net/webservices/v1/geocodeservice/geocodeservice.svc?wsdl
3) Add a references to the Silverlight map control.
4) Add the reference in the MainPage.xaml file and add a map object.
5) Add in a reference to your Bing Maps Application Key. I prefer to add this to the map from code behind when the page loads.
6) Add a mouse click event handler to the map and make a call to the Reverse Geocoding service.
7) Display results of Reverse Geocoding service
Below is the code used in the MainPage.xaml.cs file:
MainPage.xaml.cs |
using System; namespace BingMapsReverseGeocoding public MainPage() private void MainMap_Loaded(object sender, RoutedEventArgs e) MyMap.MouseClick += new EventHandler<MapMouseEventArgs>(MyMap_MouseClick); private void MyMap_MouseClick(object sender, MapMouseEventArgs e) ReverseGeocodeRequest reverseGeocodeRequest = new ReverseGeocodeRequest(); // Set the credentials using a valid Bing Maps key reverseGeocodeRequest.Location = location; // Make the reverse geocode request private void geocodeService_ReverseGeocodeCompleted(object sender, ReverseGeocodeCompletedEventArgs e) if (geocodeResponse.Results.Count > 0) |
Below is the code used in the MainPage.xaml file:
MainPage.xaml |
<UserControl x:Class="BingMapsReverseGeocoding.MainPage" |
A complete working source code can be found here:
http://cid-e7dba9a4bfd458c5.skydrive.live.com/self.aspx/VE%20Sample%20code/BingMapsReverseGeocoding.zip
Great Help ! Thanks !
Have you used the suds call from Python to specify a ConfidenceFilter on the GeocodeRequest call? I’m just not seeing how to build filters to specify in the calls options paramter.
I haven’t used Python and the Bing Maps SOAP services. Personally I haven’t used the SOAP services in years. The Bing Maps REST services are much better and faster.