Tag: geolocation

Configuring Location and Map Functionality in SharePoint 2013

SharePoint 2013 introduces a new field type named Geolocation that enables you to annotate SharePoint lists with location information. In columns of type Geolocation, you can enter location information as a pair of latitude and longitude coordinates in decimal degrees or retrieve the coordinates of the user’s current location from the browser if it implements the W3C Geolocation API. In the list, SharePoint 2013 displays the location on a map powered by Bing Maps. In addition, a new view named Map View displays the list items as pushpins on a Bing Maps Ajax control V7 with the list items as cards on the left pane.
1

Step 1 – Get & Set a Bing Maps API Key at the Farm or Web Level

SharePoint 2013 uses Bings Maps to render the map of the location. To be able to use the Bing Maps feature, you need to create a Bing Maps key and set the key at the web or farm level. You’ll see an error message on the map if you do not use a valid Bing Maps key or if a key is not set at the web that contains the list or at the farm level.

The Bing Maps key can be set at the farm or web level. To set the Bing Maps key at the farm level, you need administrator rights on the server; you can then add the key by using the SharePoint 2013 Management Shell. To set the Bing Maps key at the web level, write a console application that uses the SharePoint client object model.
In our case, we are going to use the PowerShell method to apply the Bing API Key at the farm level. First step is to grab an API key from https://www.bingmapsportal.com/:
2

Once registered, go to “Create or View Keys”:

3

A bit about the keys:

You are able to create two keys (Trial or Basic) for most application types and one additional Windows Store app Trial key under this account. Trial keys expire after 90 days and cannot be converted to Basic keys. You cannot delete keys or generate more than 3 keys from this account. If you intend to create a non-trial application, make one of the keys a Basic key and read the governing TOU that defines usage limits.
There are two types of keys, Trial and Basic.  The details of both key types can be found here: https://www.bingmapsportal.com/application/Whats/1100949

In our case, since we are using it on a production portal, we are going to use the Basic key of the Public Website sort:

 4
Grab the generated key and run the following Administrative PowerShell on any of your SharePoint 2013 Servers:
Set-SPBingMapsKey –BingKey “Enter your key here”

Your farm will now be activated for that particular Bing API key.

Full reference: http://msdn.microsoft.com/en-us/library/jj163283

Step 2 – Install SQLSysClrTypes.msi on each SharePoint Web Front-End Server

An MSI package named SQLSysClrTypes.msi must be installed on every SharePoint front-end web server to view the geolocation field value or data in a list. This package installs components that implement the new geometry, geography, and hierarchy ID types in SQL Server 2008. By default, this file is installed for SharePoint Online.
However, it is not for an on-premises deployment of SharePoint Server 2013. You must be a member of the Farm Administrators group to perform this operation. To download SQLSysClrTypes.msi, see Microsoft SQL Server 2008 R2 SP1 Feature Pack for SQL Server 2008, or Microsoft SQL Server 2012 Feature Pack for SQL Server 2012 in the Microsoft Download Center.

Step 3 – Add a GeoLocation column to a SharePoint 2013 List

Out of the box, even when you have a Bing API key applied to your farm, there is still no way to leverage GeoLocation data at the SharePoint List data – you must first programmatically  add a List field of the type GeoLocation. The following PowerShell takes a SharePoint Site and List name as input parameters and will add the field with the displayname “GeoLocation” to said List:

Param(
 [parameter(Mandatory=$true)]
 $webUrl,
 [parameter(Mandatory=$true)]
 $listName
 )

 Add-PSSnapin Microsoft.SharePoint.Powershell -ErrorAction SilentlyContinue

$fieldXml = "<Field Type='Geolocation' DisplayName='Location' />"

$web = Get-SPWeb $webUrl
 $list = $web.Lists[$listName]

$list.Fields.AddFieldAsXml($fieldXml,$true,[Microsoft.SharePoint.SPAddFieldOptions]::Default)
 $list.Update()
Save the to a file named Add-SPGeoField.ps1 file and you can execute the following command from PowerShell:

Add-SPGeoField.ps1 -webUrl http://mySharePointSite -listName MyListName

You may want to go to your SharePoint and ensure the newly added “Location” field is in your view:

5
That’s it! You will now have a new GeoLocation field which accepts Latitude and Longitude inputs :
6
Users can enter latitude and longitude values from the “Specify Location” link:
7
..or select the “Use My Location” (requires client side internet access) which calculates the users location based on IP Address and then display that map location in the Create/Edit/Display form for the item:
You can also create a special map view for the list/library containing a Geolocation column:
9

10