3

i am using appcelerator titanium to develop an IOS app and i want to let my app send local notification to the users in sunrise and sunset

a good tool to solve this is Yahoo weather using YQL ; however, yahoo weather is for non-commercial use only!!

i am trying to find a javascript library to calculate the sunrise/set + a database of the world's countries and cities with the latitude and longtude

have anyone ever needed the same?

Any idea.

3
  • 1
    aa.usno.navy.mil/data/docs/RS_OneDay.php , You can probably wrap it in nice ajax library Commented May 31, 2011 at 2:40
  • @ahmed: If you created something function-like in JS that calculates sunrise and sunset, can you please post it.
    – CoR
    Commented Dec 1, 2011 at 14:08
  • I've converted the Solar Positioning Algorithm from the National Renewable Energy Laboratory to Javascript and made it 'function-like'. You can get the code here. I'll improve the documentation over the next day or so. Commented Aug 22, 2012 at 23:46

4 Answers 4

7

This algorithm looks pretty wicked to solve exactly what you're looking to do.

6
  • 1
    Have anyone tried to do that algo in JS? If yes, can you please share the code. I'm having trouble getting right result...
    – CoR
    Commented Nov 29, 2011 at 21:09
  • I have done it in Python, it works. Unfortunately, it is necessary to account for degrees/radians conversion, cos/acos sin/asin etc. differences, integer division vs. float division vs. modulo division... These were my main culprits while debugging, but it was indeed very simple. Javascript coming soon. Commented Sep 27, 2012 at 5:57
  • @heltonbiker: Feel free to clone github.com/demianbrecht/js-riset and finish it off.. I haven't worked on it in months and don't see myself getting back to it anytime soon. Commented Sep 27, 2012 at 6:01
  • Thanks @DemianBrecht. I think I'll stick to quick'n'dirty for now. When my knowledge of GIT, Javascript and Geospatial Tricks (bike-ride oriented) grow enough to create some framework, I know where to come back for resources ;oP Commented Sep 27, 2012 at 16:22
  • 1
    Just translated into JS today for a project of my own. Enjoy: github.com/mcordingley/sunrise Commented Nov 15, 2013 at 19:29
1

Use NOAA's javascript routines for the solar position: here

They include a short list of cities with latitude and longitude. I think you can also get that from iOS, but here's another answer on getting it from city, state, etc.

0

I wrote a Google Gadget (javascript) for sunrise and sunset calculation based on lat/lon located here.

It was written from algorithms in Duffett-Smith 'Practical Astronomy with your Calculator'.

-1

With iOS (and likely other location enabled devices) you can get the users current location if they allow it. You can then use the local time and timezone offset to calculate the sunrise and sunset from their latitude and longitude.

It won't take into account local geographic effects on the horizon (e.g. if they are in a valley the sun will rise or set earlier than if they are on a hill) but it should be close enough. Use Google, I'm sure you'll find it - ah, I see Demian has done it for you.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.