Google表格自定义函数API:根据纬度/经度返回日出/日落+ GMT / DST偏移量 [英] Google Sheets Custom Function API: Return Sunrise/sunset + GMT/DST Offset based on lat/long
问题描述
我希望该函数根据坐标返回格式适当的GMT偏移量的日出或日落。我发现了一个不同的API,可以让您获得给定日期和地点的日出/设置时间以及提供GMT或DST抵消。
I'd like to have the function return the sunrise or sunset formatted with the appropriate GMT offset based on the coordinates. I found a different API that lets you get sunrise/set times for a given date and location as well as providing GMT or DST offset.
function SunRiseSet(lat,long,date,type) {
var response
UrlFetchApp.fetch("http://api.geonames.org/timezoneJSON?"+lat+"&lng="+long+"&username=northfacejmb"+lat+"&lng="+long+"&date="+date);
var json = response.getContentText();
var data = JSON.parse(json);
var sunrise = data.dates.sunrise;
var sunset = data.dates.sunset;
var gmtOffset = data.gmtOffset;
var dstOffset = data.dstOffset;
if (type == 1) {
return sunrise-gmtOffset;
} else {
return sunset-gmtOffset;
};
}
任何帮助表示感谢! - Jeremy
Any help is appreciated! - Jeremy
关于上下文:使用API将基于坐标的日出/设置导入Google表单
推荐答案
使用上面的大部分代码,我能够使它工作。必须在Json查询中包含[0]。另外,计算出来的DST偏移日出/集合已经准备好,所以不需要转换。
Using most of the code above, I was able to get it to work. had to include the [0] in the Json query. Also, the calculated sunrise/set with DST offset is already ready so no conversions are necessary.
function SunRiseSet(lat,long,date,type) {
var url = "http://api.geonames.org/timezoneJSON?lat="+lat+"&lng="+long+"&username=northfacejmb&date="+date;
var response = UrlFetchApp.fetch(url);
var json = response.getContentText();
var data = JSON.parse(json);
var sunrise = data.dates[0].sunrise;
var sunset = data.dates[0].sunset;
var gmtOffset = data.gmtOffset;
var dstOffset = data.dstOffset;
if (type == 1) {
return sunrise;
} else {
return sunset;
};
}
这篇关于Google表格自定义函数API:根据纬度/经度返回日出/日落+ GMT / DST偏移量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!