« Back to full topics list
0
0

I’m wondering if there’s a simple way to obtain current weather information (specifically just the current temperature) if I have a GPS location. I suspect that there must be a way to pass GPS location to one of the weather sites (weather.com, accuweather.com, etc.) via an API and receive back the temperature. But I’m not sure how. Any help would be appreciated. Thanks.

ANSWERED
Marked as spam
Posted by - Asked on January 28, 2019 9:29 am - 111 views

1 Replies

0
Private reply

Hi Ira,

You can certainly call any API from scriptr.io and read the response. I wrote a sample for you below using a third party weather service (openweathermap.org). If you want to use the same service, make sure to replace the API Key (appid parameter) with your own API Key which you can get when you create an account.

var lat = 35;
var lon = 139;
var weatherApi = "http://api.openweathermap.org/data/2.5/weather?appid=XXXXXXXXXXXXXXXXXXX&lat=" + lat + "&lon=" + lon;

var http = require("http");
var response = http.request({
		url : weatherApi
	});

if (response.status == "200") {
	var weatherInfo = JSON.parse(response.body);
	return weatherInfo;
} else {
	return "Ooops, there was a problem retrieving weather information!";
}

I hope this helps.

Julien

Marked as spam
Posted by - Replied on January 28, 2019 10:19 am

It certainly does, thank you.

I tried the sample in the Scriptr documentation under the section ”what can a script do?” , but it generated errors. Your suggestion of openweathermap.org is exactly what I needed.

Thanks again, Ira

( at January 28, 2019 9:26 pm)

You’re right, the third party used to get weather info modified their API and now it requires to be called over HTTPS only.

Thanks for informing us!

Julien

( at January 30, 2019 9:06 am)