In one of my previous post I explained how to get current user locale information like city, country, latitude, longitude, IP address using SharePoint hosted app. In this post, I have taken one further step to get the weather information of current logged in user’s location.

Follow the below steps to achieve the same results.

Create new SharePoint hosted app project inside visual studio.

Edit the “app.js” file and replace the code with below code. Remember to update the APIKey variable value in below code. You can get new APIKey from https://developer.forecast.io/register, and it is free.

url: '//freegeoip.net/json/',
type: 'POST',
dataType: 'jsonp',
success: function (location) {
GetWeatherInfo(location.latitude, location.longitude);
function GetWeatherInfo(lati, longi)
var APIkey = 'API Key'  // Get a new key from https://developer.forecast.io/register and it is free
var urlForecast = 'https://api.forecast.io/forecast/';
var unit = 'si'; // "si" is shortcut for Celsius and "us" is shortcut for Fahrenheit
url: urlForecast + APIkey + "/" + lati + "," + longi + "?callback=?&units=" + unit ,
type: 'GET',
dataType: 'jsonp',
timeout: 3500, 
success: function (data) {

On default.aspx page replace the “PlaceHolderMain” control with the following code

<asp:Content ContentPlaceHolderID="PlaceHolderMain" runat="server">
<label for="city">City: </label><label id="city"></label> <br />
<label for="country-name">Country: </label><label id="country-name"></label>  <br />
<label for="currentTemp">Current Temprature: </label><label id="currentTemp"></label> <br />
<label for="minTemp">Min Temp: </label><label id="minTemp"></label> <br />
<label for="maxTemp">Max Temp: </label><label id="maxTemp"></label> <br />
<label for="humidity">Humidity (0-1): </label><label id="humidity"></label> <br />
<label for="windSpeed">Wind Speed (km/h): </label><label id="windSpeed"></label> <br />
<label for="windBearing">Wind Bearing: </label><label id="windBearing"></label> <br />
<label for="Visibility">Visibility (km): </label><label id="visibility"></label> <br />
<label for="cloudCover">Cloud Cover: </label><label id="cloudCover"></label> <br />
<label for="pressure">Pressure (mb): </label><label id="pressure"></label> <br />
<label for="summary">Summary: </label><label id="summary"></label> <br />

Press F5 and see the magic

My Results

A user from London Office

You can build UI something like below using css once you have all the weather information in hand.

Happy SharePoint coding Smile

About Us

Follow Us

Email: contact@keapoint.com
Phone:  0208 7852 888

Registered Address: 1 Amber Close, Reading, RG6 7ED. United Kingdom

Company No. 11586817