lördag 28 december 2013

Using Bing services to validate addresses

Bing Maps services provides a feature for geocoding. A way to increase user input address quality, for example in SharePoint, is to present address quality feedback for the user. I've done that with a custom field.
This is the feedback I want to give to the user. I start to structure the application such as:
Why do I use HTTP handlers in SharePoint? In my opiniun they are easier to install than WCF services in SharePoint. But they are low level services. In order to get them to work I have to point out the assembly and the webhandler such as:
<%@ Assembly Name="OpenSMIL.Server, Version=, Culture=Neutral, PublicKeyToken=deb5cb40dd7862f6" %>
<%@ WebHandler Language="C#" CodeBehind="ValidateAddress.ashx.cs" Class="OpenSMIL.Server.ValidateAddress" %>

After that the server side development is pretty straight forward. As you can see in the image to the left the server code is divided into two seperate parts. The HTTP-handler, wich just needs some codebehind and let the other code worry about the Bing geocoding logic. And that is just a few lines of code.
And the code to ask Bing..

That's all for the services. In order to build a custom field here is a tutorial . And this article can come handy.

I'm almost done, all that is left is a XML-file describing for SharePoint about this field.

What is left now is just some JavaScript for rendering and communicating with the server. I have intentially left out jQuery and other JS libraries since it is basically just an Ajax requests.
That is it. All code is available here.