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.
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:
- 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”.
- Then I pull out the numbers for Longitude and Latitude.
- 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.
- You will need to get a key to use Bing Maps
- I had to add “amp;” to all the ampersands in the URL so that SharePoint would not give me XSL errors.
- 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.
- 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.
- 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.