Sunday, May 5, 2013

Adding geolocation field to SharePoint Online

One of the hidden gems in Sharepoint is the new geolocation field. Geolocation field 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. The reason it is hidden is because it is not available by default in SharePoint list and there is also no user interface to add it. The only way to add it is through code or powershell. There are already many posts with code samples for adding geolocation field so that wont be the topic of this post. I would suggest to you to check out this post http://zimmergren.net/technical/sp-2013-getting-started-with-the-new-geolocation-field-in-sharepoint-2013 if you want to get a good insight in those code samples. This post will describe how I have created a small wizard form for adding those fields to my SharePoint lists. I am using pure HTML and javascript so this will work both in SharePoint Online and in your on premise environment. First create a page where you wish to place this wizard. On that page add a Script Editor web part. In this web part we will add both our javascript methods and our html.
First add this javascript:


And after that add this HTML form:

Web relative URL: &nbsp
Bing Maps Key: &nbsp
List name: &nbsp
Field name: &nbsp

This will be your end result:


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.

Hope this helps you create you geolocation fields faster.

18 comments:

  1. Thanks for putting this all together. I have been banging my head against this for the last couple of days mainly because I am on SharePoint Online. I followed your instructions above and was up and running with a working geolocation field in a matter of minutes.

    ReplyDelete
  2. I have been trying to get this to work with out SP online site and all I get is object expected errors when trying to get the Client Context. Any ideas what might be wrong?

    ReplyDelete
  3. AWESOME POST! Worked as advertised Office365/E3 subscription.

    ReplyDelete
  4. My man! Took like 2 minutes to implement.

    Thanks for your contribution.

    ReplyDelete
  5. You are simply the best!!! was trying for hours to get this done via PowerShell - but your solution is fantastic!!! congratulations!!!

    ReplyDelete
  6. I was looking for a solution and crossed yours, very easy and I tested, worked perfect by sites.
    Thanks a lot

    ReplyDelete
  7. I cannot write a single line of code, but just followed your instructions (and worked out how to get a Bing Maps key) and there it was - a Location field added to my sites list. Many thanks!

    ReplyDelete
  8. Hi Borislav. Thanks for the great post.

    I'm hoping you will be able to help me. I'm trying to add a Geolocation field to a list on a SP Online subsite, where the list url is 'https://~mysite~.sharepoint.com/sites/dev/Lists/Customer'

    I have tried all the permutations of the url from https://~mysite~.sharepoint.com/sites/dev/Lists/Customer through to just the list name - Customer - and each time receive the error message (with the appropriate path name):

    Error: List 'Customer' does not exist at site with URL 'https://~mysite~.sharepoint.com'.

    Thanks in advance.

    ReplyDelete
  9. This comment has been removed by the author.

    ReplyDelete
  10. I've been able to add a geolocation field successfully to a list on my SharePoint Online tenant. I've also used a valid Bing maps key. Unfortunately no map is being displayed. When creating a new list item containing the geolocation field, I am not able to select a point from the map. I can only enter a plain text value. Also, when viewing or editing a list item, no map is displayed, just plain text. When I create a map view, just the plain text is displayed. It seems like the geolocation custom field type is not working on my tenant. Any advice?

    ReplyDelete
  11. This looks great, however it doesn't seem to work for me.

    I'm using O365/SP On line, already have a key, have a list, added a script web part to a web part page, added the script then added the html underneath.

    I get the form and enter the information but nothing happens when I click a button and no GeoLocation field appears in my list.

    This may be naïve but am I supposed to place the html before the closing script tag?

    Also, the relative URL I left at "/" because the list is in the sub-sub-site where I'm actually doing all this.

    Thanks

    ReplyDelete
    Replies
    1. Had the same problem when using Chrome, but then switch to Windows and IE and it worked fine.

      Delete
  12. Very many thanks!! Worked straight away with our 365/E3/SP online. I'd gotten mostly there but had that annoying 'get credentials, etc' message going across the middle of my maps, which this has now fixed.

    ReplyDelete
  13. As many I will add my thanks.
    Brilliant implementation of original Tobias's post http://zimmergren.net/technical/sp-2013-getting-started-with-the-new-geolocation-field-in-sharepoint-2013
    Pure teamwork without realising !

    PS: to all = use IE if it doesn't work on Office365.

    ReplyDelete
  14. Excellent post that works on the first try for me. Not often that works but I too, like several others have been scouring the internet searching for something that would work...yes! Awesome.

    ReplyDelete