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.

ahmed
  • 14,316
  • 30
  • 94
  • 127
  • 1
    http://aa.usno.navy.mil/data/docs/RS_OneDay.php , You can probably wrap it in nice ajax library – parapura rajkumar May 31 '11 at 02:40
  • @ahmed: If you created something function-like in JS that calculates sunrise and sunset, can you please post it. – CoR Dec 01 '11 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](https://github.com/kybernetikos/SolarPosition). I'll improve the documentation over the next day or so. – kybernetikos Aug 22 '12 at 23:46

4 Answers4

7

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

Pang
  • 9,564
  • 146
  • 81
  • 122
Demian Brecht
  • 21,135
  • 5
  • 42
  • 46
  • 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 Nov 29 '11 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. – heltonbiker Sep 27 '12 at 05:57
  • @heltonbiker: Feel free to clone https://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. – Demian Brecht Sep 27 '12 at 06: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 – heltonbiker Sep 27 '12 at 16:22
  • 1
    Just translated into JS today for a project of my own. Enjoy: https://github.com/mcordingley/sunrise – Michael Cordingley Nov 15 '13 at 19:29
  • JS version: https://gist.github.com/Tafkas/4742250 (disclaimer: NOT mine, I just stumbled upon it just before I stumbled upon this page; I don't know if / how good it works) – RobIII Oct 28 '18 at 00:20
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.

Community
  • 1
  • 1
mattexx
  • 6,456
  • 3
  • 36
  • 47
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'.

TreyA
  • 3,339
  • 2
  • 20
  • 26
-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.

RobG
  • 142,382
  • 31
  • 172
  • 209