Select to view content in your preferred language

BUG: Javascript Slowing Down S123 Field App and Connect

28
0
yesterday
cfransen
Emerging Contributor

I have this javascript which has worked for years, and then as of recent doesn't work most of the time and causes the surveys in the field app to load very slowly.  Has anyone else had issues with javascript in their surveys recently?  

// Query the Open Weather API
// https://openweathermap.org/api
// How to get started with the API: https://openweathermap.org/appid

function runWeatherCalcs(lat, lon, time) {
    // Check to make sure we have latitude, longitude and an API key
    if (lat == null || lon == null || time == null) {
        return "";
    }

    // Create the request object
    var xmlhttp = new XMLHttpRequest();

    // Format the URL with the input parameters
    var lat_param = "lat=" + lat;
    var lon_param = "lon=" + lon;
    var time_param = "dt=" + time;
    var key_param = "appid=********************";
    var format_param = "format=json";
    var units_param = "units=imperial";

    var parameters = [lat_param, lon_param, time_param, key_param, format_param, units_param].join("&");
    var url = "https://api.openweathermap.org/data/3.0/onecall/timemachine?" + parameters;

    // Make the request
    xmlhttp.open("GET", url, false); // synchronous
    xmlhttp.send();

    // Check the response. 200 indicates success from the API
    if (xmlhttp.status != 200) {
        return "";
    } else {
        var responseJSON = JSON.parse(xmlhttp.responseText);

        if (responseJSON.error) {
            return "";
        } else {
            if (responseJSON) {
                return JSON.stringify(responseJSON);
            } else {
                return "";
            }
        }
    }
}

 

0 Kudos
0 Replies