Geo location Field in SharePoint 2013
Last year I wrote a series of articles on a mash up between a SharePoint list and Bing Maps, it was a three part article and took quite a lot of time to get the end result.
Thankfully in SharePoint 2013 Preview, Microsoft has added the functionality in to achieve this fairly easily. This is achieved with a Geo location field. This field stores location information i.e. Longitude/Latitude which can then be rendered on a Bing/Nokia Map. The one downside is that you’re going to need to crack out Visual Studio 2012 in order to add this field, or at least this is what the examples say on MSDN. Hopefully this is added in to the interface by release, I couldn’t find it anywhere however.
Before you get started sort out the following pre-reqs:
- SharePoint 2013 Preview Farm
- Visual Studio 2012
- Bing Maps API Key Available Here
The first stop is to register the Bing Maps Key against SharePoint; you can achieve this using PowerShell with the following command:
Set-SPBingMapsKey –BingKey “
You can also do this via code see how here. This will make it easy if you’re packaging up an application that takes advantage of these features.
The next thing to do is to add a new custom list, in this example I have created one called “Office Locations”. In this example I have renamed “Title” to “Name” and added an “About” column of type multi-lines of text.
When you’re done the list should look similar to the following:
Open up Visual Studio 2012 and create a new Console Application, in this example I have just given it a name of AddGeoField.
The first thing we need to do is add assembly references to the two following dll’s:
Open the class (.cs) file and add a using statement at the top of the file:
|c# |||copy code |||?|
Now we need to add the code to the console application I have made this generic to read in the arguments, this way we can reuse the same console application anywhere in our farm.
|c# |||copy code |||?|
static void Main(string args)
Console.WriteLine("Location field added successfully");
private static void AddGeolocationField(string args)
// Replace site URL and List Title with Valid values.
ClientContext context = new ClientContext(args);
List oList = context.Web.Lists.GetByTitle(args);
oList.Fields.AddFieldAsXml(<Field Type='Geolocation' DisplayName='Location'/>, true, AddFieldOptions.DefaultValue);
Build the solution and then run the application from the command line, replace the arguments with ones relevant to your environment. Make sure the account your running under has sufficient permissions to access the site collection/web/list.
AddGeoField.exe http://sp2013 “Office Locations”
Now if we go back to our list, we can see the Location column has been added of type Geolocation.
When adding a new item, we can either use the current location which will be useful for devices with GPS built in, or add the longitude/latitude of the current location.
When you click specify location, a second modal popup opens where you can specify the values required:
Once valid values have been entered, a Bing map preview is displayed to give you a indication that you have the co-ordinates correct.
After adding a few office locations, the list will look similar to the following:
You can view the Bing Map in various ways:
Opening a list item:
Clicking on the icon in the geo location field, this is a great way for a fast preview:
Lastly, you can also now create a map view, if you create a new view, you will see a Map View type.
When I was creating my view I got an error, but the view created anyway, when you switch to it you get a awesome representation of all the list items.
I think you would agree this is a lot easier than what we had to do in previous versions of SharePoint. I would love to see uses you can come up with when you put this in to practice.
If you want to save some time I have uploaded my compiled solution for you to use: Add Geo Location (449)