Geolocation field in SharePoint 2013

In this article I’ll show what this field does, a sample of creating and using the field, getting and setting the Bing Maps keys to make sure our maps are properly working and displaying.

What are the location and map features 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.
Create a plan list called Location
1

The same list, with the Geolocation field added to it

When we’ve added the Geolocation field to support our Bing Maps, you can see that a new column is displayed in the list view and you can interact with it. In my sample here I’ve filled in the coordinates for the four office locations  I’ve listed in my list.

2

Pressing the small globe icon will bring up a nice hover card kind of dialog with the actual map.
3
Viewing an actual list item looks like this, with the map fully integrated by default into the display form
4
when edit the item it looks like this. in this you have to mention location. you need to specify you location by longitude and latitude. and also you can use “use my location”  option but your browser should supports the usage and tracking of your location.
5

now enter your longitude and latitude.

6

Adding a Geolocation Field to your list

let’s move on to the actually adding the field to our list.  you can definitely add it using code and scripts, which is my preferred way to add stuff anyway.

Adding a Geolocation field using PowerShell

Add-PSSnapin Microsoft.SharePoint.PowerShell
$web = Get-SPWeb "http://url.com"
$list = $web.Lists["Stores Location"]
$list.Fields.AddFieldAsXml("<Field Type='Geolocation' DisplayName='Office Location'/>",$true,
[Microsoft.SharePoint.SPAddFieldOptions]::AddFieldToDefaultView)

Adding a Geolocation field using the .NET Client Object Model

function AddGeolocationFieldSample()
{
var clientContext = new SP.ClientContext();
var targetList = clientContext.get_web().get_lists().getByTitle('Scandinavian Microsoft Offices');
fields = targetList.get_fields();
fields.addFieldAsXml("<Field Type='Geolocation' DisplayName='Office Location'/>",true,SP.AddFieldOptions.addToDefaultContentType)
clientContext.load(fields);
clientContext.executeQueryAsync(Function.createDelegate(this, this.onContextQuerySuccess), Function.createDelegate(this, this.onContextQueryFailure));
}

Using Server Object Model:
SPWeb web = site.RootWeb;
SPList list = web.Lists.TryGetList("Stores Location");
if(list != null)
{list.Fields.AddFieldAsXml("<Field Type='Geolocation' DisplayName='Office Location'/>",true,SPAddFieldOptions.AddFieldToDefaultView);}

Bing Maps – getting and setting the credentials in SharePoint.

after field creation you need to set bing maps credential other wise you will face issue on your map. as you can see the issue in picture.
7

Get your Bing Maps keys

If you don’t have any credentials for Bing Maps, you can easily fetch them by going to the specified Url (http://www.bingmapsportal.com) and follow these few simple steps.
7
you will have to enter some information to create a new key and then click ‘Submit’
8
After you’ve clicked ‘Submit’ you’ll be presented with a list of your keys, looking something like this.
9
Great you have done now. Now we need to let SharePoint know about this as well!
we have a Property Bag on the SPWeb object called “BING_MAPS_KEY” which allows us to configure our key.

Setting the BING MAPS KEY using PowerShell on the Farm

Set-SPBingMapsKey -BingKey "FFDDuWzmanbiqeF7Ftke68y4K8vtU1vDYFEWg1J5J4o2x4LEKqJzjDajZ0XQKpFG"

Setting the BING MAPS KEY using PowerShell on a specific Web

Add-PSSnapin Microsoft.SharePoint.PowerShell
$web = Get-SPWeb "http://url"
$web.AllProperties["BING_MAPS_KEY"] = "FFDDuWzmanbiqeF7Ftke68y4K8vtU1vDYFEWg1J5J4o2x4LEKqJzjDajZ0XQKpFG"
$web.Update()
Also you can create MAP View from create views.  And now browse your list and add new item as a location……
Hope this Help 🙂 😉
Happy SharePointing
Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s