Community Tip - When posting, your subject should be specific and summarize your question. Here are some additional tips on asking a great question. X
Im trying to make this example: Tutorial: Creating a Mashup , I know the Yahoo Weather API doesnt work anymore and that I can use Weather Underground instead as I saw here: https://support.ptc.com/appserver/cs/view/solution.jsp?n=CS228421&art_lang=en , Im also using the same code, but when I try to test the service I get this error:
"Unable To Convert From org.mozilla.javascript.UniqueTag to LOCATION"
The code for my service is:
// Need to make a free wunderground.com account to get this key
var apiKey = "{381603bc1002b5ce}";
var temperature;
var humidity;
var LocationIn;
//Inputted location needs to be valid lat, long: 40.7127, 74.0059
if(LocationIn != null){
var test = LocationIn + " ";
var arrayLocations = test.split(",");
var lat = arrayLocations[0];
var long = arrayLocations[1];
var prm = {
url: "http://api.wunderground.com/api/"+apiKey+"/conditions/q/"+lat+","+long+".json",
timeout: 60
};
var json = Resources["ContentLoaderFunctions"].PostJSON(prm);
try {
temperature = parseInt(json.current_observation.temp_f);
humidity = parseInt(json.current_observation.relative_humidity);
me.Temperature = temperature;
me.Humidity = humidity;
result = "Success. Properties are updated.";
} catch(err) {
logger.error("Could not parse temperature and humidity for location: " + LocationIn
+ ". All valid Longitudes and Latitudes values must have decimal points" + " and be located where weather measurements are commonly taken (near cities).");
result = "Failed. Check Script Logs";
}
}
Im not an expert in JS and I'm new into Thingworx so thank you!
Hello,
I believe the braces in the sample article's code are meant to signify that that api key needs to be filled in with some information and are not part of the string. This line
var apiKey = "{381603bc1002b5ce}";
should actually look like this: var apiKey = "381603bc1002b5ce";
Also, you should change your code now, which you can do once logged into the Wunderground website. You only have a certain number of rest calls that you can make per day, so you don't want this key to be public knowledge.
Hope this helps!
Tori