I was looking into a map scenario a few weeks back, and came across the Bing Maps AJAX control which is controlled via JavaScript. I thought it would be cool to pull SharePoint list data via the SharePoint JavaScript client object model, and tie that into the Bing Maps AJAX control. The map control takes in a latitude and longitude, then maps the location. You can control the look of the pin icon, the map, and the description associated with the mapped location. The initial problem is that most people don’t keep track of latitude and longitude, they keep track of addresses.
Luckily the Bing Maps group thought of that, and they exposed a Geocode web service that takes in an address and returns an object with the latitude and longitude. The trick is that the web service isn’t ASP.Net AJAX aware, so you can’t just point a ServiceReference control at the end point and get a nice JavaScript proxy class back. Also, in order to authenticate to the Bing Maps web services, you need to setup an application key with the service that is passed as the ApplicationID. With those limitations, I decided to write a proxy WCF web service that is ASP.Net aware, and handles the call to the Bing Maps Geocode web service.
At the end of the day, I came up with the following sample. It’s pretty hardcoded with regards to the SharePoint List and column names. This could be taken the next step in turning this into a web part with exposed properties for which SharePoint list to pull from, and which columns make up the address. You can also be pretty creative with the look of the pin and description to make the map more interactive. The sample consists of the following:
[ServiceContract(Namespace = "")] [AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Allowed)] public class Bing_GeoCodeServiceProxy
Let’s look at what the sample looks like at runtime. When you browse, the page, it renders the text “Click here to view map”
Click the text, and the following happens:
Full sample solution is attached to the blog post. Some points to make about the sample:
I'm really glad I came across to your article as this is really helpful. Thank you for sharing this tutorial.