0

Hi currently i am working on sharePoint online, Where i need to fetch the Current location (city) of the user and on the basis of that i want to get the temperature of that city. using JScript . Please help.

  • Are you managing user's location in Active Directory? Or you just mean the location from where users are browsing site? – Atish Dipongkor - MVP Feb 22 '16 at 11:33
2

You can use below code to get current location if:

  1. User's browser supports HTML5 geolocation API; and
  2. User allows to share his/her location to your Application

        function onLocationUpdate(location) {
            var lat = location.coords.latitude;
            var lng = location.coords.longitude;
            console.log("Current location: " + lat + " " + lng);
        }
    
        if(navigator.geolocation) {
            navigator.geolocation.getCurrentPosition(onLocationUpdate);
        }
        else {
            console.log("navigator.geolocation is not available");
        }
    

As a fallback, you can use this API to get the Longitude and Latitude from user's IP address.

Once you've got the location, you can make a call to below API passing the Longitude and Latitude you've found:

http://forecast.weather.gov/MapClick.php?lat=<<Latitude>>&lon=<<Longitude>>&FcstType=json

You will get weather data in JSON format, which you can parse temperature data.

1

Try this SPServices method:

var thisUserID = $().SPServices.SPGetCurrentUser({
    fieldName: "Office",
    debug: false
});

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.