Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Calculate Sunrise and Sunset times - port code to Android

I'm looking to create a simple calculator that will generate the sunrise and sunset for a given location (gps) for android.

I've come across these two approaches:

http://www.codeproject.com/KB/cs/suntimes.aspx http://williams.best.vwh.net/sunrise_sunset_algorithm.htm

I'd just like some advice on the best way to approach this. I have a feeling that I could spend a lot of time on either approach and discover it's too compicated.

What approach would you suggest is best? I think the C# would probably be best. The lack of the .NET libraries would be a pain to convert.

Any advice appreciated.

Thanks.

like image 465
jim Avatar asked Sep 20 '25 10:09

jim


2 Answers

Look at com.android.server.TwilightCalculator and TwilightService in android sources (but not in the compiled jar for some reason...). I haven't used it, but looks convenient, also calculates twilight dates.

like image 138
John the Helpful Avatar answered Sep 22 '25 04:09

John the Helpful


The easiest route is to grab an algorithm written i c, for examle http://souptonuts.sourceforge.net/code/sunrise.c.html and use JNI to call it from your Android application. For this you will need the Android NDK. Just download and install the NDK and you will find some good sample code that shows you how to do it.

like image 29
Robert Avatar answered Sep 22 '25 05:09

Robert