How to calculate the sunrise and sunset in javascript?

↘锁芯ラ 提交于 2019-12-07 12:31:21

问题


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.


回答1:


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




回答2:


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.




回答3:


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'.




回答4:


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.



来源:https://stackoverflow.com/questions/6182451/how-to-calculate-the-sunrise-and-sunset-in-javascript

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!