4

I'm trying to find the geolocation column in my SharePoint 2013 site. I heard that it was out of the box functionality that should be included with all SharePoint 2013 packages, is that true? Do I have to turn it on somewhere?

0

I've done it through C# with the following function passing the site url where the list lives and the name of the list you wish the column to be added too. In my case the column is called/titled Geolocation (You will have to implement the main function to call AddGeolocationField below:

private static void AddGeolocationField(String siteUrl, String listTitle)
{
        ClientContext context = new ClientContext(siteUrl);
        List oList = context.Web.Lists.GetByTitle(listTitle);
        oList.Fields.AddFieldAsXml("<Field Type='Geolocation' DisplayName='Geolocation'/>", true, AddFieldOptions.AddToAllContentTypes);
        oList.Update();
        context.ExecuteQuery();
} 

The reason I did it through C#was that the rest of my program populates the list with necessary data read in from an Excel file. So I've just been using this when its been required to add to a list.

0

This is how I achieved it in my SharePoint Online tenant using HTML and JS (source: My SharePoint Insight Blog). It's a reusable wizard so can be reused on various lists

  1. Create a page where you wish to place this wizard
  2. On that page add a Script Editor web part. In this web part we will add both javascript methods and html.
  3. Add javascript:

    <script type="text/javascript">
    var clientContext;
    var relativeAdress;
    
    function AddGeolocationField() {
      ClearNotifications();
      GetRelativeAdress();
        clientContext = new SP.ClientContext(relativeAdress);  
        var web = clientContext.get_web();
    
        var targetList = web.get_lists().getByTitle(document.getElementById('listname_input_id').value);
        var fields = targetList.get_fields();
        fields.addFieldAsXml(
            "<Field Type='Geolocation' DisplayName='" + document.getElementById('fieldname_input_id').value + "'/>",
            true,
            SP.AddFieldOptions.addToDefaultContentType);
    
        clientContext.load(fields);
        clientContext.executeQueryAsync(function (sender, args) {
       document.getElementById('success_id').innerHTML = "You have succesfully created new geolocation field.";
    },
    function (sender, args) {
        document.getElementById('error_id').innerHTML = "Error: "+args.get_message();
    });
    }
    
    
    function SetBingKey() {
      ClearNotifications();
      GetRelativeAdress();
        clientContext = new SP.ClientContext(relativeAdress);
    
        var web = clientContext.get_web();
        var webProperties = web.get_allProperties();
    
        webProperties.set_item("BING_MAPS_KEY", document.getElementById('bing_key_id').value);
        web.update();
        clientContext.load(web);
    
        clientContext.executeQueryAsync(function (sender, args) {
            document.getElementById('success_id').innerHTML = "You have succesfully entered BING map key on "+web.get_title()+" site";
        }, function (sender, args) {
              document.getElementById('error_id').innerHTML = "Error: "+args.get_message();
        });
    }
    
    function GetBingKey() {
    
      ClearNotifications();
       GetRelativeAdress();
    
        clientContext = new SP.ClientContext(relativeAdress);
        var web = clientContext.get_web();
    
        var webProperties = web.get_allProperties();
    
        clientContext.load(webProperties);
    
        clientContext.executeQueryAsync(function (sender, args) {
            document.getElementById('bing_key_id').value = (webProperties.get_fieldValues()["BING_MAPS_KEY"]);
    
        }, function (sender, args) {
            document.getElementById('bing_key_id').value = "";
            document.getElementById('error_id').innerHTML = "Property not found! Please check your web site relative URL.";
        });
      }
    
      function ClearNotifications(){
      document.getElementById('success_id').innerHTML = "";
      document.getElementById('error_id').innerHTML = "";
    }
    
          function GetRelativeAdress(){
     if (document.getElementById('webrelative_url_id').value === "")
            relativeAdress = "/";
        else
            relativeAdress = document.getElementById('webrelative_url_id').value;
    if(relativeAdress.charAt(0)!='/')
     document.getElementById('error_id').innerHTML = "Relative adress has to start with /";
     }
    

  4. And after that add this HTML form:

    <table style="width: 480px;">
    <tbody>
    <tr>
        <td style="width: 200px;">Web relative URL:
        </td>
        <td style="width: 5px;">&nbsp
        </td>
        <td valign="top"><input id="webrelative_url_id" name="relative" value="/" type="text">
            <label style="font-size: 8pt;">
                * Input web relative URL and select "Get BING key" to check if key is set</label>
        </td>
          <td style="text-align: right;" valign="top"><input onclick="GetBingKey()" value="Get BING key" type="button">
        </td>
         </tr>
        <tr>
            <td style="width: 200px;" valign="top">Bing Maps Key:
              </td>
            <td style="width: 5px;">&nbsp
          </td>
          <td valign="top"><input id="bing_key_id" name="bingkey" type="text">
              <label style="font-size: 8pt;">
                  * Input Bing map key and relative url to web site to wich you wish to add the key</label>
        </td>
        <td style="text-align: right;" valign="top"><input onclick="SetBingKey()" value="Set BING key" type="button">
        </td>
    
    
        </tr>
    <tr>
            <td style="width: 200px;" valign="top">List name:
           </td>
           <td style="width: 5px;">&nbsp
           </td>
            <td valign="top"><input id="listname_input_id" name="listname" type="text">
            <label style="font-size: 8pt;">
                * Name of the list where you wish to add your new geolocation field</label>
        </td>
        <td></td>
        </tr>
    <tr>
                <td valign="top">Field name:
            </td>
             <td style="width: 5px;">&nbsp
                      </td>
                     <td valign="top"><input id="fieldname_input_id" name="fieldname" type="text">
                      <label style="font-size: 8pt;">
                          * Name of the new geolocation field you wish to add</label>
            </td>
            <td style="text-align: right;" valign="top"><input onclick="AddGeolocationField()" value="Create field" type="button">
           </td>
        </tr>
    </tbody></table>
    <label id="error_id" style="color: red;">
    </label>
    <label id="success_id" style="color: green;">
    </label>
    
  5. And now you have your form for adding geolocation field anywhere on your site collection. Once you have entered relative path to your web ("/" is root web) you can use Get Bing key to check if you have a BING maps key placed in that web and with Set BING key you can change or add a BING maps key to that web.

And once you enter List name and Field name you can use Create field to add a geolocation field with the name you specified to the list on the web.

0

The geolocation column is not enabled by default. You can enable it using PowerShell or C#.

Below is the PowerShell script to do it; don't forget to specify your site url and your list's name.

Add-PSSnapin Microsoft.SharePoint.PowerShell -ErrorAction SilentlyContinue;

$Web = Get-SPWeb "<your_site_url>";
$List = $Web.Lists["<your_list_name>"];
$FieldXml = "<Field Type ='Geolocation' DisplayName='Location' />";

$List.Fields.AddFieldAsXml($FieldXml, $true, [Microsoft.SharePoint.SPAddFieldOptions]::AddFieldToDefaultView);

Reference: SP 2013: Getting started with the new Geolocation field in SharePoint 2013


You can also enable the field on the web (site column) instead of a specific list. Just replace the last line above with the code below:

$Web.Fields.AddFieldAsXml($FieldXml);
$Web.Update();

Reference: Powershell to add a geolocation site column in SharePoint 2013

0

Please refere this link you must run below powershell script where you want to use this column

https://blogs.msdn.microsoft.com/ritazh/2012/10/20/powershell-to-add-a-geolocation-site-column-in-sharepoint-2013/

0

You cannot find the column in GUI. But still if you want to use that column into your list then there are multiple ways of adding GeoLocation fields to your list.

Using Powershell

Add-PSSnapin Microsoft.SharePoint.PowerShell $web = Get-SPWeb "siteUrl" $list = $web.Lists["ListName"] $list.Fields.AddFieldAsXml( "", $true, [Microsoft.SharePoint.SPAddFieldOptions]::AddFieldToDefaultView)

using the .NET Client Object Model

var webUrl = "siteUrl";
ClientContext ctx = new ClientContext(webUrl);
List officeLocationList = ctx.Web.Lists.GetByTitle("List Name");
officeLocationList.Fields.AddFieldAsXml( "", true, AddFieldOptions.AddToAllContentTypes);
officeLocationList.Update();
ctx.ExecuteQuery();

using the Javascript Client Object Model

function AddGeolocationFieldSample()
{
    var clientContext = new SP.ClientContext(); 
    var targetList = clientContext.getweb().getlists().getByTitle('List Name'); 
    fields = targetList.get_fields(); 
    fields.addFieldAsXml( "", true, SP.AddFieldOptions.addToDefaultContentType); 
    clientContext.load(fields); 
    clientContext.executeQueryAsync(Function.createDelegate(this, this.onContextQuerySuccess),Function.createDelegate(this, this.onContextQueryFailure));
}

using the Server Side Object Model

// Assumes you've got an SPSite object called 'site'
SPWeb web = site.RootWeb;
SPList list = web.Lists.TryGetList("List Name");
if (list != null) {
    list.Fields.AddFieldAsXml("", true, SPAddFieldOptions.AddFieldToDefaultView);
}

you can find detail description here

-1

As explained by others geo-location is a standard capability that is fully supported by Microsoft but it has no standard web UI to make it readily accessible.

For on prem deployments of SP2013 I have written a freely downloadable solution which puts a web UI around this capability. It also uses the Bing Map API to provide automatic address look up capabilities. That way your users can work in street addresses (something they understand) rather than in lat/long pairs (something they won't).

All information, including download links, can be found in my blog at http://www.kaboodlekonnect.com/colin/Lists/Posts/Post.aspx?ID=43

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.