After countless hours of trying to crack this code, I’m faced with a final hurdle. The challenge lies in parsing the output from the and storing either the sunrise or sunset time into a variable that can be exported as a result in a Google Sheet.
The ultimate goal is to create a custom function in the Google Sheet that can be utilized like any other formula:
A1=SunRiseSet(lat,long,date,type)
This should yield a result like "5:11:12 PM". The ‘type’ parameter is included to specify whether to return the sunrise or sunset value.
Here’s an excerpt of the existing code:
function SunRiseSet(lat,long,date,type) {
var response = UrlFetchApp.fetch("https://api.sunrise-sunset.org/json?lat="+lat+"&lng="+long+"&date="+date);
var json = response.getContentText();
Logger.log(json);
var data = JSON.stringify(json);
Logger.log(data);
var data = json;
var sunrise = data.sunrise;
var sunset = data.results.sunset
type=1;
if(type==1){
return this.sunrise}
else{
return this.sunset};
}
While it might seem straightforward, my attempts at solving this have hit a dead end. Your assistance would be greatly appreciated! Thank you!