I am trying to calculate the next sun event using the following code. Can you identify something in this code that will result in a faster battery drain?
var sc = new SunCalc();
var lat;
var lon;
var timeNextEvent = "--:--";
var loc = Activity.getActivityInfo().currentLocation;
if (loc == null)
{
lat = Application.getApp().getProperty(LAT);
lon = Application.getApp().getProperty(LON);
}
else
{
lat = loc.toDegrees()[0] * Math.PI / 180.0;
Application.getApp().setProperty(LAT, lat);
lon = loc.toDegrees()[1] * Math.PI / 180.0;
Application.getApp().setProperty(LON, lon);
}
if(lat != null && lon != null)
{
var sunrise_moment = null;
var sunset_moment = null;
var now = Time.now();
sunrise_moment = sc.calculate(now, lat.toDouble(), lon.toDouble(), SUNRISE);
sunset_moment = sc.calculate(now, lat.toDouble(), lon.toDouble(), SUNSET);
if(now.greaterThan(sunrise_moment) && now.lessThan(sunset_moment))
{
var nextInfo = Gregorian.info(sunset_moment, Time.FORMAT_SHORT);
timeNextEvent = nextInfo.hour.format("%02d") + ":" + nextInfo.min.format("%02d");
}
else if(now.greaterThan(sunset_moment))
{
var next = sc.calculate(Time.now(), lat.toDouble(), lon.toDouble(), SUNRISE);
var nextInfo = Gregorian.info(next, Time.FORMAT_SHORT);
timeNextEvent = nextInfo.hour.format("%02d") + ":" + nextInfo.min.format("%02d");
}
}