Geo Location field - a hidden gem - hidden SP 2013 field (On Prem & 0365)
Integrates with Bing Maps to show locations
Have tried this on SP online and works great !!!
Below is the screenshot for the list view to which the geo location field was added
To add a new location - just specify the title and the Latitude and Longitude for the same as shown in figure below :-
One needs to have a BING MAP Key for this to work
Freely available on bing maps
This key is to be set as Property Bag for the current web
One can use this cool code to create admin screen to easily setup geolocation fields
Just enter the web url
Set the Bing Maps Key
Specify your list and column name
And readily use your geolocation field
Here is the admin screen -
Here is the code :-
HTML Code :-
<table style="width: 480px;">
<tbody>
<tr>
<td style="width: 200px;">Web relative URL:
</td>
<td style="width: 5px;"> 
</td>
<td valign="top"><input id="webrelative_url_id" name="relative" type="text" value="/">
<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()" type="button" value="Get BING key">
</td>
</tr>
<tr>
<td style="width: 200px;" valign="top">Bing Maps Key:
</td>
<td style="width: 5px;"> 
</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()" type="button" value="Set BING key">
</td>
</tr>
<tr>
<td style="width: 200px;" valign="top">List name:
</td>
<td style="width: 5px;"> 
</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;"> 
</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()" type="button" value="Create field">
</td>
</tr>
</tbody></table>
<label id="error_id" style="color: red;">
</label>
<label id="success_id" style="color: green;">
</label>
Also - need to install SQL CLRTypes on WFE's
Integrates with Bing Maps to show locations
Have tried this on SP online and works great !!!
Below is the screenshot for the list view to which the geo location field was added
To add a new location - just specify the title and the Latitude and Longitude for the same as shown in figure below :-
One needs to have a BING MAP Key for this to work
Freely available on bing maps
This key is to be set as Property Bag for the current web
One can use this cool code to create admin screen to easily setup geolocation fields
Just enter the web url
Set the Bing Maps Key
Specify your list and column name
And readily use your geolocation field
Here is the admin screen -
Here is the code :-
HTML Code :-
<table style="width: 480px;">
<tbody>
<tr>
<td style="width: 200px;">Web relative URL:
</td>
<td style="width: 5px;"> 
</td>
<td valign="top"><input id="webrelative_url_id" name="relative" type="text" value="/">
<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()" type="button" value="Get BING key">
</td>
</tr>
<tr>
<td style="width: 200px;" valign="top">Bing Maps Key:
</td>
<td style="width: 5px;"> 
</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()" type="button" value="Set BING key">
</td>
</tr>
<tr>
<td style="width: 200px;" valign="top">List name:
</td>
<td style="width: 5px;"> 
</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;"> 
</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()" type="button" value="Create field">
</td>
</tr>
</tbody></table>
<label id="error_id" style="color: red;">
</label>
<label id="success_id" style="color: green;">
</label>
Javascript Code :-
<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 /";
}
</script>
Also - need to install SQL CLRTypes on WFE's
http://blog.baslijten.com/sharepoint-2013-geolocation-column-a-component-is-not-installed/
Reference - http://mysharepointinsight.blogspot.com/2013/05/adding-geolocation-field-to-sharepoint.html



No comments:
Post a Comment