Quantcast
Channel: SharePoint – Be Awesome @
Viewing all articles
Browse latest Browse all 19

SharePoint 2013 Geolocation

$
0
0

Geolocation or ‘spatial data’ is a new feature in SharePoint 2013 and it provides the ability to store data representing the latitude and longitude coordinates of an object right in your SharePoint list. The continued growth of mobility and mobile applications requires location aware data.  Now you can easily provide this type of information in your SharePoint data.

Enabling Geolocation

Activation of Geolocation has two parts.  The first is the connection to the Bing Maps service.  This requires you to register and request an api key.  You can do this on http://bingmapsportal.com.  Geolocation will work without this, but your maps show the message that your farm does not contain a Bing Maps key across the center of your map.  Once you have a key, apply it in PowerShell with the following command:

Set-SPBingMapsKey -BingKey $yourKey

This only needs to be done once for your farm.  If the key should change, the Set command can be called again to replace the value.  There is also a Get-SPBingMapsKey , which will retrieve this information.

The second step requires adding a field of type=’Geolocation’ to the list  The bad news about this step is that it is not available for the end user to add to their list from the browser, at least not out-of-the-box.  It must be added through code.  Good news is you have some options for implementing the code.  It can be run as a PowerShell script.  It can be run in a console application.  It can also be run on feature activation, for example, when creating a new list as part of a feature.  However you choose to do it, the process is the same.  Get the SPWeb object, Get the SPList where you want to add the field.  Call the AddFieldAsXml method on the Fields property of the list.  This method takes a string which is the xml definition of the field.

Here is what it looks like in PowerShell

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

#get spweb object
$web = Get-SPWeb($weburl)

# get list
$list = $web.Lists[$listName]

# first param – string with xml
# second param – add to default view
$list.Fields.AddFieldAsXml($fieldXml, $true)

#call update on the list.
$list.Update()

This is great if you only want to add the Geolocation column one list at a time.  If you modify the above code and add the field to the SPWeb object, instead of the SPList object, you now have a ‘Site Column’ with the Geolocation type. 

$fieldXml = "<Field Type = ‘Geolocation’ DisplayName=’Geo Location’ Name=’geolocation’ Group=’custom fields’/>"

#get spweb object
$web = Get-SPWeb($weburl)

# first param – string with xml
$web.Fields.AddFieldAsXml($fieldXml)

#call update on the web.
$web.Update()

A Site Column can be added to any list on the site from the ‘Add From Existing Columns’ link in the list settings.  You have now allowed the end user to add this column to any list on their site.  So now that this column is there, what can we do with it?

Using Geolocation

The geolocation field holds two values, the latitude and the longitude of the global position for the item in the list.  If you are at the location you want to use for the list item, this information can be automatically populated by clicking the ‘Use My Location’ link on this field.  This will then make a client-side call to determine location based on the IP information of the device making the call.  It does not require GPS on the device. 

The automatic method limits the locations you can enter for the list item, unless of course you spend a lot of time traveling.  So, this data can also be populated manually by the end user.  There are many sites that can provide these values given an address.  Bing Maps provides this data as well.  Enter an address in and click the zoom link for the address.

image

Once you zoom to this spot, right click on the spot.  This new information window contains links for directions and navigation, but also the latitude and longitude of the spot.  This same dialog displays when right-clicking anywhere on the map so you can find the geolocation data for any place on the map just by interacting with the map..

image

 

Viewing Geolocation

Now that geolocation is enabled and you can enter data, how is this information displayed in the SharePoint list?  When I added the geolocation column in PowerShell, it was also added to the default view.  The field displays a globe icon and clicking it presents a Bing Map with the corresponding point pinned at the center of the map.  This small of the view of the map provides scroll and zoom features.  The location can also be loaded in a Bing Maps page to leverage the all of the map features by clicking the View on Bing Maps link at the bottom of the window..

image

The addition of the geolocation column on the list also provides a new view template for creating custom Map Views for the list.  The columns selected to include in the view are displayed for each item listed in the view.  The items are presented on the left side in a listview type control with their locations noted on the map to the right.  The display area of the map will zoom out to display all of the locations.

image



Viewing all articles
Browse latest Browse all 19

Latest Images

Trending Articles



Latest Images