I am not sure if it really is related to Android, but since I am going to use it for an Android app, I am tagging Android too.
I am trying to build some logic to calculate sunrise time if lat-long are given.
I've tried following, but everything gives a slightly different time of the Sunrise of the location I provide it with (of Bangalore, India), and when I search for google with the keyword Bangalore Sunrise
Google gives a different result in the card which looks more accurate:
All give different results, and still Google's looks to be more acccurate.
Does anybody here know of an API or a better calculation for this? Or the algorithm/webservice that Google is using for their cards?
Any help is much appreciated.
Indian standard time is UTC+05:30, that's probably why you are seeing a 30 min difference.
The algorithm can calculate sunrise time in UTC, but it won't be able to convert UTC to local time, which requires complicated timezone knowledge. The algorithm probably does something very simplistic, like
localTime = utcTime + 1_hour * longitude / 15_degree
which is 5 hours for city of Banglore.
You should take the UTC time, then convert it to local time by using Java date APIs.
I haven't studied all the links you gave, but most likely the differences stem from different assumptions & definitions. In particular, the following factors tend to vary from algorithm to algorithm:
There are certainly other factors as well, and the problem becomes increasingly ill-defined as latitude gets farther from the equator. But these factors alone can account for minutes of difference.
A quick search lead me to this api
http://www.earthtools.org/webservices.htm#sun
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With