Bing Maps recently retired their SOAP web service interface. The new interface is a REST service and the JSON Data Contracts define the response interface. There is a sample program Parsing REST Services JSON Responses that I used as a starting point for my code which is located here.
To use the Bing Maps interface you will need a key. See Getting a Bing Maps key if you don’t have one already. In my code I read the key from the environment variable named “BingMapsKey”:
The base of the URI for all requests is:
With this base we add “Locations” then the search string and add the key at the end. Be sure to use WebUtility.UriEncode on your location search.
Next we make a call with Web API to the service using the MakeRequestWebApi function with “New York” in the place string. The Tuple that is returned has a status string and Bing Response object.
Once we get a Response object back, we have to cast to the object that we requested, in this case a Location. The other objects are Route, Traffic Incident, CompressedPointList, ElevationData, or SeaLevelData.
The function ProcessLocationResponse is from the original program and shows the locations found with high confidence and their geocode points.
I also needed to get route instructions from the Bing Map interface. I added a Location search for three more specific addresses to make a cross country musical journey from the Brill Building in New York to the Whiskey A Go Go in LA with a stop by the Stax Studios in Memphis.
The Route parameter requires at least two waypoints in the request. The MakeWayPointString takes a List of Locations and builds the string.
The ProcessRouteResponse parses the route information and shows the instructions and coordinates of each itinerary item in both legs of the trip.