14 August 2013

SharePoint 2013 Geo Location Field & Map

SharePoint 2013 Provide a new field type (column type) called Geo location. This field is used to enter the longitude and latitude data. SharePoint out Of the Box will provide an association to a Bing map to the entered Geo Location. A list Created with Geo Location field will also can have a Map View in which a map will be displayed aside the list with the pinned entered Geo location. When you hover the Geo Location in the list the corresponding location will be highlighted in the map.

The Site column contain a field called “Location” , But this field will not be the right thing to add for Geo Location. We cannot add Geo Location field using SharePoint 2013 UI.
Use the following code to create a Geo Location field to a List.

private static void CreateGeolocationField()
{
  // Replace site URL and List Title with Valid values.
  ClientContext context = new ClientContext("<site url>");
  List myList = context.Web.Lists.GetByTitle("list Title");
  myList.Fields.AddFieldAsXml("<Field Type='Geolocation' DisplayName='Location'/>", true,   AddFieldOptions.AddToAllContentTypes);
  myList.Update();
  context.ExecuteQuery();
}
 
You can also use power shell command for the same.
A map view of the list can be created using UI.

No comments:

Post a Comment