Using CQWP to display SharePoint Geolocation Field

I really like the functionality that has been added by the geolocation field in SharePoint 2013.  It can be extremely useful when you have projects and people all over the world.  A map view can give you a quick idea of where everything is in relation to each other.  However, one of the major limitations that I have run into is that you cannot set the default zoom level when looking at individual items.  It starts at the street level when I would much prefer to see it at the country or even regional level.  So I used the good old content query web part (CQWP) to come to my rescue.

I live in Ghana, so let’s start out by choosing a location just about in the center of the country.  If you look at the images in the gallery below you will note that the default street level view is completely useless because Bing maps does not see any streets around.  This means that I end up with a blank map.  I have realized that I can use the scroll wheel on my mouse to zoom out. That is not only annoying, but many users may not realize they can even do it.  I tried a few different list views and ran into even worse situations.  In the standard list view the geolocation field is simply shown as a globe icon which you have to click on to view the individual map (which is still zoomed in too far).  I tried the “Box Style” which then just gives me the map point information “Point (-1.178895 8.32924)”.  Perhaps Neo from the Matrix could use that to visualize a map in his head, but not me.

This slideshow requires JavaScript.

I needed a way to show the map at a much higher level.  So I started working with a CQWP to first parse the geolocation field and then display the Bing map.  Here is what the final template looks like (click on it to get the full size view):


Here is what I am trying to accomplish with the code:

  1. The geolocation comes across as “Point (-1.178895 8.32924)”.  The first step is to get rid of the extra text and end up with just “-1.178895 8.32924”.
  2. Then I pull out the numbers for Longitude and Latitude.
  3. I build my URL for the image that I want to return from Bing Maps.  You can read Microsoft’s information on how to get a static map.
    1. You will need to get a key to use Bing Maps
    2. I had to add “amp;” to all the ampersands in the URL so that SharePoint would not give me XSL errors.
  4. I chose to concatenate the latitude and longitude information into the URL variable that I built.  I include it at the beginning to set the center point of the map and at the end to set the pinpoint.
  5. A feature I then added was a link to Bing Maps so that the user could explore the map further since the map that I was displaying was static.  I had first tried to use an embedded map that was interactive, but it goofed up the rest of my SharePoint page for some reason.  I was able to include the @Title of the list item in the link so that when it is viewed on the Bing maps page the user remembers what they are looking at.  You can read Microsoft’s information on how to create a map URL.
  6. Finally I handled situations where there was no geolocation field to display.

In the end I have a map view that is zoomed out the regional level and gives my users a link to a larger interactive map.

End Goal: zoomed out map
End Goal: zoomed out map

4 thoughts on “Using CQWP to display SharePoint Geolocation Field

  1. This is great, Paul! The addition of geolocation data in SharePoint 2013 is awesome, but I’ve been under them impression that you can’t turn it out without PowerShell. Is that how you did it?


    1. Tobias Zimmergren has an excellent article on the geolocation field and all the different ways that you can add it including PowerShell and JavaScript. Then I found another post where Borislav Grgić took the information from Tobias and wrote all the code that you would need to put into a script editor so that you can just fill out a simple form on your site to add a geolocation field to any list.

      The bummer is that on SharePoint Online you cannot add a geolocation field as a site column, you can only add it to a list. I still don’t understand why this is not something that can be added from the web interface on SP. I had originally set out to build this map project on a Content Search Web Part (CSWP) but that relies on search functionality which relies on site columns so I couldn’t find a way to expose the geolocation field to the CSWP. If anybody finds a way to add geolocation as a site column on SP Online I would love to hear about it.

Leave a Reply

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

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

Google+ photo

You are commenting using your Google+ 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 )


Connecting to %s