GeoLocation Field in SharePoint 2013
By Anatoly Mironov
In SharePoint 2013 Preview there is a new type of field: GeoLocation which is, like the old SPUrlField, a pair of values. The geolocation is described as longitude and latitude. Unfortunately you can’t add this field in list settings. You have to create this in code. In the provided link you can find the code C# code which uses the Client Object Model. In another link you can find an example how to create the geolocation file using Server Object Model (in FeatureActivated EventReceiver). If you know me, you might already know that I will propose a JavaScript solution. Here is the code to create a geolocation field in an existing list using JSOM:
var ctx = SP.ClientContext.get\_current(),
list = ctx.get\_web()
.get\_lists()
.getByTitle("CheckIns"),
fields = list.get\_fields();
fields.addFieldAsXml("<Field Type='Geolocation' DisplayName='Location'/>", true);
list.update();
ctx.load(list);
ctx.executeQueryAsync();
```Add the location in the UI. There you can define long and lat, or use your current location: [![](https://sharepointkunskap.files.wordpress.com/2012/10/geo-001.png "geo-001")](https://sharepointkunskap.files.wordpress.com/2012/10/geo-001.png) To add a list item with a geolocation we can use jsom as well. This code adds a new list item with [Cheboksary geolocation](http://www.bing.com/maps/?v=2&where1=56.13%2047.23&mkt=en-US&encType=1):
var ctx = SP.ClientContext.get_current(), list = ctx.get_web() .get_lists() .getByTitle(“CheckIns”), itemCreateInfo = new SP.ListItemCreationInformation(), item = list.addItem(itemCreateInfo), point = “POINT (47.23 56.13)”; item.set_item(‘Title’, ‘Cheboksary’); item.set_item(‘Location’, point); item.update(); ctx.load(item); ctx.executeQueryAsync();