How to create a simple app with MapPoint web services
We will create a simple Windows form that displays a map image utilizing MapPoint web services. Of course, you can find most of this information on the web, but starting with MapPoint Web Services can be a bit overwhelming. So, we will start out with the basics by establishing a developer account first. Click on this link to get an account. You will need a Windows Live account to sign up.
Sign-in with your Windows Live account and fill out the required information.
Once you receive the email, click on the provided link and you should receive an “Account Creation Successful” message. It will require you to change your password. After changing your password, you will be redirected to the Bing Maps Customer Services site.
Click on Verify Credentials to test you user ID and password.
Then Click on Developer Resources to get the MapPoint Web Service WSDL url. Developer accounts can only using staging.
Here you can access the MapPoint Web Service SDK information and examples.
Now that we have established a developer account and received the WSDL, we can begin to implement the Windows form.
You can find most of the information for displaying a map in your Windows form here.
We will only have 2 controls on the form . First, Drag a picture box and button control on your form.
Now add a Web Reference by
Add Service Reference -> Advanced -> Add Web Reference ( Enter the WSDL url)
Now we will add a class to establish a connection to four services.
MapPoint Web Service consists of four constituent services: common, find, render, and route.
- Common Service – contains utility functions for find, route and render services.
- Find Service – locate addresses, geographic entities, and latitude and longitude coordinates.
- Render Service – used for drawing maps of routes and locations, placing pushpins, etc. Think of this service as the visual service including getting map images.
- Route Service- Generate directions, etc.
To receive more details on these services. Click here
If you want to add in your own information, there is the Customer Data Service.
Customer Data Service is a XML Web Service that allows you to upload, download, and manage custom data sources.
I have created a class, MapPointServices, to establish the connections to all the services.
“Bing Maps Developer Account ID”,
“Bing Maps Developer Account password”);
// Create the render service
renderService = new RenderServiceSoap();
renderService.Credentials = ourCredentials;
renderService.PreAuthenticate = true;
// Create the find service
findService = new FindServiceSoap();
findService.Credentials = ourCredentials;
findService.PreAuthenticate = true;
// Create the route service
routeService = new RouteServiceSoap();
routeService.Credentials = ourCredentials;
routeService.PreAuthenticate = true;
// Create the common service
commonService = new CommonServiceSoap();
commonService.Credentials = ourCredentials;
commonService.PreAuthenticate = true;
In the same class, create properties to access all the service objects: commonService, routeService, findService, and renderService. Make sure you change the credentials with your credentials that you established above.
Now, go to your form and add a button click event. In the button click event add the following code.
FindServiceSoap findService = services.FindService;
FindSpecification findSpec = new FindSpecification();
findSpec.DataSourceName = “MapPoint.NA”;
findSpec.InputPlace = “Seattle, WA”;FindResults foundResults = findService.Find(findSpec);
ViewByHeightWidth[] myViews = new ViewByHeightWidth[1];
myViews[0] = foundResults.Results[0].FoundLocation.BestMapView.ByHeightWidth;
RenderServiceSoap renderService = services.RenderService;
MapSpecification mapSpec = new MapSpecification();
mapSpec.DataSourceName = “MapPoint.NA”;
mapSpec.Views = myViews;
MapImage[] mapImages = renderService.GetMap(mapSpec);
if (mapImages != null)
{
// Display the map:
Bitmap bmapImg = new Bitmap(new MemoryStream(mapImages[0].MimeData.Bits));
this.pictureBox1.Image = bmapImg;
}
The services.FindService is a property to access the find service object from the MapPointServices class. The picturebox1 is the picture box control we added previously.
We are done! Now press F5 to run and you should see your map.


