How to calculate the sunrise and sunset in javascript?

杀马特。学长 韩版系。学妹 提交于 2019-12-05 22:50:12
Demian Brecht

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

mattexx

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.

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

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.

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