Many developers use the Bing Maps API’s REST services to perform spatial queries such as geocoding an address or calculating routes and distances. The Bing Maps REST services are nice and fast, however, using them from a .NET application used to require a decent amount of work.
The Bing Maps .NET REST Toolkit makes it easy to use these services from your .NET application by providing a portable class library. This library wraps the Bing Maps REST services and implements best practices to ensure good performance and the most accurate results are returned.
In the past, it could easily take an hour or more to add the Bing Maps REST services to their .NET application. Now, with the aid of a NuGet package in the toolkit, you can implement Bing Maps REST services in minutes. You can find this project on GitHub here.
How to use the .NET REST Toolkit
Add the REST Toolkit to your project
In Visual Studio, open the NuGet Package Manager
, select the Browse tab and search for “Bing Maps REST”. This will reduce the list of results enough to find the “BingMapsRESTToolkit” package.
If you want to verify that you have the correct package, the listed owner of the package is bingmaps and the author is Microsoft. Install the package into your project.
Alternatively, if you are using the NuGet command line:
PM> Install-Package BingMapsRESTToolkit
Call the Bing Maps REST services using the .NET Toolkit
The Bing Maps .NET REST Toolkit has two key components, a service manager and a set of request classes. The ServiceManager is a static class that makes it easy to asynchronously process any Bing Maps REST request. Here is a list of the different requests classes available:
- ElevationRequest
- GeocodeRequest
- ImageryMetadataRequest
- ImageryRequest
- ReverseGeocodeRequest
- RouteMajorRoadsRequest
- RouteRequest
- TrafficRequest
The ServiceManager class has two static methods: GetResponseAsync and GetImageAsync. The GetResponseAsync method will return a Response object from the Bing Maps REST services which aligns with the documented Response object for the REST services. The GetImageAsync method will return a stream containing the image data.
The following is an example of how to make a geocode request and get the response from the Bing Maps API REST service from your .NET app.
|
The following is an example of how to request a map image from the Bing Maps API REST services to retrieve the image stream with the .NET toolkit.
|
Bing and Open Source
The Bing Maps API team has been working towards being more involved in the Open Source community, and open source REST service support for .NET apps is just one of many examples. Here are a few other open source projects released by the team that you may be interested in.
- Bing Location Control helps devs add location to the conversation
- New Bing and Cognitive Services APIs samples added to the Bot Builder samples repo
- TypeScript Definitions for Bing Maps V8 Released on GitHub
We’re always working to help developers push the envelope with intuitive mapping solutions and useful resources. Create a free Bing Maps API key to build your next mapping app on a robust platform.